自定义GCMBroadcastReceiver

时间:2015-03-17 14:57:38

标签: android

我目前正在创建一个这样的广播接收器: 在我的片段中:

receiver=new GcmBroadcastReceiverLobby();
IntentFilter filter =new IntentFilter("com.google.android.c2dm.intent.RECEIVE");
filter.setPriority(9999);
filter.addAction("com.google.android.c2dm.intent.RECEIVE");
getActivity().registerReceiver(receiver, filter);

class GcmBroadcastReceiverLobby extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        String messageType = extras.toString();
        setResultCode(Activity.RESULT_CANCELED);
        abortBroadcast();
    }
}

问题是intent.getExtras不返回GCM-Message的详细信息。

<receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="de.battlestr1k3.gamelobbies" />
        </intent-filter>
    </receiver>

    <service android:name=".GcmIntentService" android:exported="true" />

GcmBroadcastReceiverLobby具有更高的优先级,因此它首先捕获通知。我可能错过了代码中的权限?

extras.toString()

返回Bundle [mParcelledData.dataSize = 280]

1 个答案:

答案 0 :(得分:0)

好的,我添加了

if (!extras.isEmpty()) {  

} 它工作了