也許第二組眼睛可以幫助我。似乎無法在我的Receiver中獲取任何內容,即使我在從我的服務器發佈到gcm發送url時發送成功。在服務器上成功發送GCM消息但在設備上未收到GCM消息
清單:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="<pkgname>.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="<pkgname>.permission.C2D_MESSAGE" />
<receiver
android:name="<pkgname>.GcmBroadcastReceiver"
android:exported="true"
android:permission="com.google.android.gcm.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<pkgname>" />
</intent-filter>
</receiver>
<service android:name="<pkgname>.GcmIntentService" />
= com.myappsname我已經刪除它爲了保密
這裏是服務器請求和響應:
{"registration_ids":[removed],"data":{"project":{"comment":"Chubb","username":"Dave Thomas","time":"2014-12-05 15:33:13","projectId":5}}}
{"multicast_id":removed,"success":2,"failure":0,"canonical_ids":1,"results":[{"message_id":"removed"},{"registration_id":"removed","message_id":"removed"}]}
所以服務器成功發送。 ..但根本沒有看到應用程序端的任何東西。在接收器的onReceive方法的開始處設置一個斷點,並且它沒有捕獲任何東西。
接收器:
package <pkgname>;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
更新發現了這個在我的日誌,所以我知道設備實際上歌廳消息:
12-08 12:48:42.910: W/BroadcastQueue(960): Permission Denial: broadcasting Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=<pkgname> (has extras) } from com.google.android.gsf (pid=28999, uid=10007) requires com.google.android.gcm.c2dm.permission.SEND due to receiver <pkgname>/.GcmBroadcastReceiver
我想我已經找到了我的問題
如果您正在使用Android Studio/Gradle for Android,請牢記您的類別ory需要成爲你的'applicationId',以防與清單中的'package'有所不同。 – CommonsWare 2014-12-06 00:14:15
使用eclipse和ADT。感謝評論! – 2014-12-06 00:16:01