MyFirebaseInstanceIDService
“ onTokenRefresh()
”未触发。主要活动没有代码。我只是在主节xml中提到了该服务。
我正在发送代码和输出,请有人提出一些解决方案。我成功连接了它们。这是图片。 。
请有人提出一些建议,以便我克服它。
等级
:应用
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.live.bbw.liveapp"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-messaging:10.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
:项目
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
服务
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
{
private static final String TAG = "MyFirebaseIIDService";
public static final String REGISTRATION_SUCCESS = "RegistrationSuccess";
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.v("TEST", "Refreshed token: " + refreshedToken);
}
private void sendRegistrationToServer(String token) {
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "TEST";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
//It is optional
Log.v(TAG, "From: " + remoteMessage.getFrom());
Log.v(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
//Calling method to generate notification
sendNotification(remoteMessage.getNotification().getBody());
}
//This method is only generating a push notification
//It is same as we did in earlier posts
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Firebase Push Notification")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
输出量
03-05 16:29:23.420 2526-2526/? I/PMFunc: prepare 0 com.live.bbw.liveapp
03-05 16:29:23.420 2526-2526/? I/art: Late-enabling -Xcheck:jni
03-05 16:29:23.450 2526-2526/? D/Environment: 111 rawUserId = 0
03-05 16:29:23.450 2526-2526/? D/AndroidKeyStoreProvider: overseas product
03-05 16:29:23.870 2526-2526/com.live.bbw.liveapp D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
03-05 16:29:23.960 2526-2526/com.live.bbw.liveapp D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
03-05 16:29:24.010 2526-2536/com.live.bbw.liveapp W/art: Suspending all threads took: 17.653ms
03-05 16:29:24.060 2526-2526/com.live.bbw.liveapp I/FA: App measurement is starting up, version: 10084
03-05 16:29:24.060 2526-2526/com.live.bbw.liveapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-05 16:29:24.060 2526-2526/com.live.bbw.liveapp D/FA: Debug-level message logging enabled
03-05 16:29:24.060 2526-2526/com.live.bbw.liveapp D/FA: AppMeasurement singleton hash: 927531083
03-05 16:29:24.120 2526-2526/com.live.bbw.liveapp V/FA: Collection enabled
03-05 16:29:24.120 2526-2526/com.live.bbw.liveapp V/FA: App package, google app id: com.live.bbw.liveapp, 1:994131540882:android:f9dd91f670fe6909
03-05 16:29:24.120 2526-2526/com.live.bbw.liveapp I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.live.bbw.liveapp
03-05 16:29:24.200 2526-2526/com.live.bbw.liveapp V/FA: Registered activity lifecycle callback
03-05 16:29:24.210 2526-2526/com.live.bbw.liveapp I/FirebaseInitProvider: FirebaseApp initialization successful
03-05 16:29:24.220 2526-2526/com.live.bbw.liveapp I/InstantRun: starting instant run server: is main process
03-05 16:29:24.230 2526-2590/com.live.bbw.liveapp V/FA: Using measurement service
03-05 16:29:24.250 2526-2590/com.live.bbw.liveapp V/FA: Connecting to remote service
03-05 16:29:24.500 2526-2526/com.live.bbw.liveapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-05 16:29:24.530 2526-2536/com.live.bbw.liveapp W/art: Suspending all threads took: 28.247ms
03-05 16:29:24.590 2526-2526/com.live.bbw.liveapp V/FA: onActivityCreated
03-05 16:29:24.620 2526-2526/com.live.bbw.liveapp D/PhoneWindow: DEBUG_SYSTEMUI:origin statusbar style
03-05 16:29:24.620 2526-2526/com.live.bbw.liveapp D/PhoneWindow: DEBUG_SYSTEMUI:windowDrawsFlag set
03-05 16:29:24.620 2526-2526/com.live.bbw.liveapp D/PhoneWindow: DEBUG_SYSTEMUI:IconColor=1
03-05 16:29:24.620 2526-2526/com.live.bbw.liveapp D/PhoneWindow: DEBUG_SYSTEMUI:StatusBarColor final set ff303f9f
03-05 16:29:25.020 2526-2536/com.live.bbw.liveapp W/art: Suspending all threads took: 16.817ms
03-05 16:29:25.020 2526-2590/com.live.bbw.liveapp V/FA: Using measurement service
03-05 16:29:25.020 2526-2590/com.live.bbw.liveapp V/FA: Connection attempt already in progress
03-05 16:29:25.020 2526-2590/com.live.bbw.liveapp V/FA: Activity resumed, time: 195978479
03-05 16:29:25.040 2526-2526/com.live.bbw.liveapp I/ViewRootImpl: CPU Rendering VSync enable = true
03-05 16:29:25.040 2526-2653/com.live.bbw.liveapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-05 16:29:25.050 2526-2526/com.live.bbw.liveapp D/Atlas: Validating map...
03-05 16:29:25.130 2526-2653/com.live.bbw.liveapp I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8916_32_LA.BR.1.1.3.C14__release_AU (Ic4528faa6f)
OpenGL ES Shader Compiler Version: E031.25.03.04
Build Date: 06/14/16 Tue
Local Branch: mybranch20312125
Remote Branch: quic/LA.BR.1.1.3.c14_1
Local Patches: NONE
Reconstruct Branch: NOTHING
03-05 16:29:25.130 2526-2653/com.live.bbw.liveapp I/OpenGLRenderer: Initialized EGL, version 1.4
03-05 16:29:25.150 2526-2653/com.live.bbw.liveapp D/OpenGLRenderer: Enabling debug mode 0
03-05 16:29:25.300 2526-2526/com.live.bbw.liveapp W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-05 16:29:25.330 2526-2590/com.live.bbw.liveapp D/FA: Connected to remote service
03-05 16:29:25.330 2526-2590/com.live.bbw.liveapp V/FA: Processing queued up service tasks: 2
03-05 16:29:25.340 2526-2526/com.live.bbw.liveapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@27de329c time:70826474
03-05 16:29:29.885 2526-2590/com.live.bbw.liveapp V/FA: Inactivity, disconnecting from the service
03-05 16:29:34.505 2526-2590/com.live.bbw.liveapp V/FA: Session started, time: 195988506
03-05 16:29:34.505 2526-2590/com.live.bbw.liveapp I/FA: Tag Manager is not found and thus will not be used
03-05 16:29:34.515 2526-2590/com.live.bbw.liveapp D/FA: Logging event (FE): _s, Bundle[{_o=auto, _sc=MainActivity, _si=3883244167549912924}]
03-05 16:29:34.545 2526-2590/com.live.bbw.liveapp V/FA: Using measurement service
03-05 16:29:34.545 2526-2590/com.live.bbw.liveapp V/FA: Connecting to remote service
03-05 16:29:34.555 2526-2590/com.live.bbw.liveapp D/FA: Connected to remote service
03-05 16:29:34.555 2526-2590/com.live.bbw.liveapp V/FA: Processing queued up service tasks: 1
03-05 16:29:39.595 2526-2590/com.live.bbw.liveapp V/FA: Inactivity, disconnecting from the service
03-05 16:34:21.528 2526-11478/com.live.bbw.liveapp V/FA: Recording user engagement, ms: 297023
03-05 16:34:21.528 2526-11478/com.live.bbw.liveapp V/FA: Using measurement service
03-05 16:34:21.528 2526-11478/com.live.bbw.liveapp V/FA: Connecting to remote service
03-05 16:34:21.548 2526-11478/com.live.bbw.liveapp V/FA: Activity paused, time: 196275492
03-05 16:34:21.548 2526-11478/com.live.bbw.liveapp D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=297023, _sc=MainActivity, _si=3883244167549912924}]
03-05 16:34:21.638 2526-11478/com.live.bbw.liveapp V/FA: Using measurement service
03-05 16:34:21.638 2526-11478/com.live.bbw.liveapp V/FA: Connection attempt already in progress
03-05 16:34:21.638 2526-11478/com.live.bbw.liveapp D/FA: Connected to remote service
03-05 16:34:21.638 2526-11478/com.live.bbw.liveapp V/FA: Processing queued up service tasks: 2
03-05 16:34:26.368 2526-2536/com.live.bbw.liveapp W/art: Suspending all threads took: 7.783ms
03-05 16:34:26.708 2526-11478/com.live.bbw.liveapp V/FA: Inactivity, disconnecting from the service
03-05 16:34:28.408 2526-2536/com.live.bbw.liveapp W/art: Suspending all threads took: 27.545ms
03-05 16:34:30.328 2526-2526/com.live.bbw.liveapp D/FA: Service connection suspended
03-05 16:34:30.338 2526-2526/com.live.bbw.liveapp D/FA: Service connection suspended
03-05 16:34:30.338 2526-2526/com.live.bbw.liveapp D/FA: Service connection suspended
感谢您
吉特·达斯古普塔
最佳答案
每当生成新令牌时,就会触发onTokenRefreshcallback
在以下情况下,注册令牌可能会更改:
该应用程序删除实例ID
该应用已在新设备上还原
用户卸载/重新安装应用程序
用户清除应用程序数据。
因此,如果您正在手机中调试该应用程序,则除非发生上述情况之一,否则不会调用onTokenRefresh()
。
更多信息在这里:
https://firebase.google.com/docs/cloud-messaging/android/client
关于android - 不调用MyFirebaseInstanceIDService“onTokenRefresh”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49109494/