gpt4 book ai didi

java - 一段时间后应用程序崩溃并出现 TokenRefresher 异常

转载 作者:行者123 更新时间:2023-12-02 02:56:05 27 4
gpt4 key购买 nike

我遇到了这个问题,我尝试解决但没有成功。我正在 Firebase (FCM) 中使用云消息传递向特定设备发送推送通知。我部署了该功能,一切正常,只是每隔 4 或 5 分钟后我的应用程序总是崩溃

E/AndroidRuntime: FATAL EXCEPTION: 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'
}

最佳答案

document

getToken() 方法已弃用。支持getInstanceId()

您可以使用 FirebaseMessagingService 来接收 token

像这样

public class HandleFirebaseMessagingService extends FirebaseMessagingService 
{

@Override
public void onNewToken(String s) {
super.onNewToken(s);
Applog.d("FCM", "FirebaseToken: " + s);

}}

关于java - 一段时间后应用程序崩溃并出现 TokenRefresher 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57073378/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com