服务器正在使用设备ID向应用发送推送通知。该应用必须接收并向用户显示通知。该应用程序已在GCM中注册,推送通知适用于IOS。现在用android测试。 Android应用程序必须只接收后端发送的通知。但是没有收到消息。
我为GCM收集的日志如下:
11-11 17:06:09.139 10265-10265/? I/PCWCLIENTTRACE_PushUtil: getPushTypeList : [SPP, GCM]
11-11 17:06:10.729 3506-4220/? D/ActivityManager: retrieveServiceLocked(): component = com.google.android.gms/com.google.android.gms.gcm.GcmService; callingUser = 0; userId(target) = 0
11-11 17:06:14.249 10265-10298/? I/PCWCLIENTTRACE_PushUtil: getPushTypeList : [SPP, GCM]
11-11 17:06:14.329 10265-10300/? D/PCWCLIENTTRACE_PCWHandler: [ensureRegistration] - MG registered : GCM
11-11 17:07:27.389 3506-3915/? V/BroadcastQueue: [background] Process cur broadcast BroadcastRecord{19bd6d1 u0 com.google.android.gms.gcm.ACTION_CHECK_QUEUE} DELIVERED for app ProcessRecord{38a314d8 4539:com.google.process.gapps/u0a13}
11-11 17:07:27.439 3506-4581/? D/ActivityManager: retrieveServiceLocked(): component = com.google.android.gms/com.google.android.libraries.social.autobackup.AutoBackupGcmTaskService; callingUser = 0; userId(target) = 0
11-11 17:08:34.659 10676-10676/? I/PCWCLIENTTRACE_PushUtil: getPushTypeList : [SPP, GCM]
11-11 17:11:54.029 4539-6262/? I/GCM: GCM message GSYNC_TICKLE 0:1447222313784217%e7a71353318775cf
11-11 17:11:54.179 3506-4634/? D/ActivityManager: retrieveServiceLocked(): component = com.google.android.gsf/com.google.android.gsf.subscribedfeeds.GCMIntentService; callingUser = 0; userId(target) = 0
11-11 17:11:54.579 3506-4643/? D/ActivityManager: retrieveServiceLocked(): component = com.google.android.gms/com.google.android.gms.gcm.http.GoogleHttpService; callingUser = 0; userId(target) = 0
11-11 17:14:54.039 4539-6262/? I/GCM: GCM message GSYNC_TICKLE 0:1447222413012818%e7a71353318775cf
11-11 17:14:54.069 3506-4683/? D/ActivityManager: retrieveServiceLocked(): component = com.google.android.gsf/com.google.android.gsf.subscribedfeeds.GCMIntentService; callingUser = 0; userId(target) = 0
以下是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.clinicloud.app" >
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.clinicloud.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.clinicloud.app.permission.C2D_MESSAGE" />
<application
android:name=".application.GlobalDataAccess"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GCMTestActivity"
android:label="@string/title_activity_gcmtest"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- for Gingerbread GSF backward compat -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.clinicloud.app" />
</intent-filter>
</receiver>
<!-- [START gcm_listener] -->
<service
android:name="com.clinicloud.app.MyGcmListenerService"
android:exported="false" >
<intent-filter>```````````````````
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
</application>
</manifest>
以下是我的GCMListener服务
@Override
public void onMessageReceived(String from, Bundle data) {
Log.d(TAG,"**********************************************************Inside onMessageReceived =>");
String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
Log.d(TAG,"**********************************************************Send notification message =>"+message);
if (from.startsWith("/topics/")) {
// message received from some topic.
Log.d(TAG,"*************************************************************************Message =>"+message);
} else {
// normal downstream message.
Log.d(TAG,"**************************************************************************Message downstream =>"+message);
}
sendNotification(message);
}
我在我的依赖项中添加了编译'com.google.android.gms:play-services-gcm:8.1.0'
如果我遗漏了任何内容,请告诉我......我无法理解为什么没有调用GCM侦听器服务。