Android Studio SDK 30 Gradle 7
通知を受け取ることができます。
しかし、デバイストークンを取得できません:(
FirebaseInstanceId.getInstance に関する Web 上のすべての回答は非推奨であり、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 はトリガーされず、ログ cat には「newToken」が表示されません:(
誰かがこれを修正する方法を知っていますか?