Android не может получить токен устройства FirebaseInstanceId.getInstance() устарел

Android Studio SDK 30Gradle 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» :(

кто-то знает, как это исправить?

1 ответ

Окончательно,

Я нашел нужную документацию

https://firebase.google.com/docs/cloud-messaging/android/client

Другие вопросы по тегам