我正在将我的应用更新为新的GCM 7.5,而我注意到Google改变了很多内容。 看看我的代码
public class GcmIntentService extends GcmListenerService {
public static final int NOTIFICATION_ID = 1;
private static final String TAG = "MyGcmListenerService";
public GcmIntentService() {
super();
}
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from);
String message2 = data.getString("payload");
String title = data.getString("title");
String type = data.getString("push_type");
Log.i(TAG, "Message: " + message2 + " PushType:" + type + "title" + title);
for (String key : data.keySet())
{
Log.d("Bundle Debug", key + " = \"" + data.get(key) + "\"");
}
// parseMessage(data);
// sendNotification(message);
}
@Override
public void onDeletedMessages() {
// sendNotification("Deleted messages on server");
}
@Override
public void onMessageSent(String msgId) {
// sendNotification("Upstream message sent. Id=" + msgId);
}
@Override
public void onSendError(String msgId, String error) {
// sendNotification("Upstream message send error. Id=" + msgId + ", error" + error);
}
现在进入我的问题:收到的数据为空,除了我记录了捆绑包还有折叠密钥。
的Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.was.abcd"
android:versionCode="404080000"
android:versionName="4.8.0" >
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false"
android:xlargeScreens="true" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<!-- * Google Cloud Messaging -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.was.abcd.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.was.abcd.permission.C2D_MESSAGE" />
<!-- Google Cloud Messaging * -->
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="@bool/largeheap"
android:theme="@style/Theme.FullScreen" >
<!-- * Google Cloud Messaging -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Google Cloud Messaging * -->
<activity
android:name="com.magazine.screens.ShelfActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.magazine.screens.SplashActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.magazine.screens.ReaderActivity"
android:configChanges="keyboardHidden|screenSize"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name="com.magazine.screens.PurchaseActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.magazine.screens.FacebookActivity"
android:configChanges="orientation"
android:hardwareAccelerated="true"
android:icon="@drawable/fb_logo"
android:screenOrientation="portrait" >
</activity>
<!-- * Google Cloud Messaging -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.was.abcd" />
</intent-filter>
</receiver>
<activity
android:name="com.magazine.messaging.NotificationDialogActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
<service
android:name="com.magazine.messaging.GcmIntentService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name" >
</activity>
</application>
答案 0 :(得分:0)
请看一下这些要点:
WakefulBroadcastReceiver
代替InstanceId
。#define
作为前者已被弃用。希望有所帮助!!