我有这个问题,我试图解决但没有成功。 我正在Firebase(FCM)中使用云消息传递将推送通知发送到特定设备。我部署了该功能,并且一切正常,只是每隔4或5分钟,我的应用就会始终崩溃
E / AndroidRuntime:致命例外:TokenRefresher。
每次用户打开应用程序(启动屏幕加载后)以及用户登录时,我都将tokenID存储在我的Firestore文档中。 下面是我存储代码的方式。
我需要帮助以了解正在发生的事情。
FirebaseInstanceId.getInstance().getInstanceId()
.addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
//Get device token id here
String deviceToken = instanceIdResult.getToken();
//Store device token id in user document
firebaseFirestore.collection("Users")
.document(userID).update("token_id", deviceToken)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
//On success direct user to main activity
Intent toMain = new Intent(SignIn.this, MainActivity.class);
toMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(toMain);
finish();
Bungee.fade(SignIn.this);
}else{
Toast.makeText(SignIn.this,Objects.requireNonNull(task.getException())
.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
});
这是我的gradle文件
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config
.disableVersionCheck = true
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.ibrahimsahko.zee"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.Binary-Finery:Bungee:master-SNAPSHOT'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-firestore:17.0.1'
implementation 'com.github.irfaan008:IRBottomNavigationView:1.0.1'
implementation 'com.gauravk.bubblenavigation:bubblenavigation:1.0.7'
implementation 'com.github.hsmnzaydn:imagezoom:1.2.1'
implementation 'com.google.firebase:firebase-messaging:17.3.3'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'id.zelory:compressor:2.1.0'
}
答案 0 :(得分:0)
如document所说
getToken()方法已过时。
赞成getInstanceId()
。
您可以使用FirebaseMessagingService
来接收令牌
像这样
public class HandleFirebaseMessagingService extends FirebaseMessagingService
{
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Applog.d("FCM", "FirebaseToken: " + s);
}}