如何解决android 无法检索设备令牌 FirebaseInstanceId.getInstance() 已弃用
Android Studio SDK 30 摇篮 7
我可以收到通知。
但无法获取设备令牌:(
网络上关于 FirebaseInstanceId.getInstance 的所有答案都已弃用 并用 FirebaseInstanceId.getInstance 代码回答:(
Android 不要让我使用它
我拥有的 androidManifest
<service
android:name=".MyFirebaseMessagingService"
android:exported="false"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
在 build.gradle 我有
classpath 'com.google.gms:google-services:4.3.5'
在模块级别
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-messaging:21.0.1'
implementation 'com.google.firebase:firebase-core:18.0.2'
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:26.5.0')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
apply plugin: 'com.google.gms.google-services'
在创建的类中
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(@NonNull String token) {
super.onNewToken(token);
Log.e("newToken",token);
//Add your token in your sharepreferences.
getSharedPreferences("_",MODE_PRIVATE).edit().putString("fcm_token",token).apply();
}
但是这个 onNewToken 从来没有触发过,日志猫从来没有显示“newToken”:(
有人知道如何解决这个问题吗?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。