我使用Firebase向所有应用程序用户发送通知,但即使Firebase显示消息状态为Complete,我仍然没有在设备中获取消息(使用模拟器)。
这是我的代码: MyFirebaseMessagingService类:
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
/**
* Created by -SAMSUNG- on 06/12/2017.
*/
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("myLog","NotificationTitle : "+remoteMessage.getNotification().getTitle());
}
}
MyFirebaseInstanceIDService类:
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
/**
* Created by -SAMSUNG- on 06/12/2017.
*/
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
super.onTokenRefresh();
String token = FirebaseInstanceId.getInstance().getToken();
Log.d("myLog","Token is : "+token);
}
}
这是gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.github.amigold.fundapter:library:1.0'
compile 'rongi.rotate-layout:rotate-layout:3.0.0'
compile 'me.grantland:autofittextview:0.2.+'
testCompile 'junit:junit:4.12'
compile'com.google.firebase:firebase-messaging:11.6.2'
compile 'com.google.firebase:firebase-core:11.6.2'
compile 'com.google.maps.android:android-maps-utils:0.5+'
compile 'com.google.android.gms:play-services:11.6.2'
}
apply plugin: 'com.google.gms.google-services'
这是清单:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/logofppt"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:icon">
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBOhBdH1WXX9jz9kSk8nVmoQgKaM4N0_vs" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.nobar" />
<activity
android:name=".SplashScreen"
android:theme="@style/AppTheme.nobar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TDIinfo"
android:label="TDI" />
<activity
android:name=".TCAinfo"
android:label="TCA" />
<activity
android:name=".INFOGinfo"
android:label="INFOG" />
<activity
android:name=".TRIinfo"
android:label="TRI" />
<activity android:name=".TMSIRinfo" android:label="TMSIR"/>
<activity android:name=".TLWinfo" android:label="TLW" />
<activity android:name=".J2EEinfo" android:label="J2EE"/>
</application>
这是错误:
D/FA: Logging event (FE): notification_receive(_nr), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-947096531520348892, message_device_time(_ndt)=0, message_time(_nmt)=1512583947, message_id(_nmid)=1882982486230769049}]
D/myLog: NotificationTitle : Emplois
V/FA: Connecting to remote service
W/GooglePlayServicesUtil: Google Play services out of date. Requires 11720000 but found 9683470
W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
D/FA: Logging event (FE): notification_foreground(_nf), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-947096531520348892, message_device_time(_ndt)=0, message_time(_nmt)=1512583947, message_id(_nmid)=1882982486230769049}]
V/FA: Connecting to remote service
W/GooglePlayServicesUtil: Google Play services out of date. Requires 11720000 but found 9683470
W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
V/FA: Processing queued up service tasks: 2
E/FA: Discarding data. Failed to send event to service
E/FA: Discarding data. Failed to send event to service
V/FA: Processing queued up service tasks: 0
I/art: Do partial code cache collection, code=60KB, data=50KB
I/art: After code cache collection, code=60KB, data=50KB
I/art: Increasing code cache capacity to 256KB
请!如果你有任何想法如何解决这个问题,请发表评论..
答案 0 :(得分:0)
您需要在设备上更新Google Play服务
GooglePlayServicesUtil:Google Play服务已过期。需要 11720000但发现9683470
答案 1 :(得分:0)
问题是模拟器无法接收通知,我用真实设备尝试过它并且工作正常^ _ ^