我们如何在同一个应用程序中实现GCM以及解析通知



我的应用程序有一个第三方库,在这个库中实现了解析通知通知。

但是app需要GCM的一些通知。

那么我们如何在同一个项目中实现两个接收器呢?

有没有人想在同一个应用程序中实现这两个通知?

如果可能,那么怎么做?

请帮帮我。

提前感谢。

在我看来,你只需要创建一个新的Broadcast Receiver到GCM。

或者甚至在现有的验证中添加操作验证。例如,在下面的代码中,我通过检查意图动作来检查即将到来的动作是来自GCM的注册推送还是我的推送。

if (intent != null) {
        String action = intent.getAction();
        Log.w(TAG, "Registration Receiver called");
        if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
            Log.w(TAG, "Received registration ID");
            final String registrationId = intent.getStringExtra("registration_id");
            String error = intent.getStringExtra("error");
            Log.d(TAG, "dmControl: registrationId = " + registrationId + ", error = " + error);
            // TODO Send this to my application server
        } else {
//Your code here
}

你的滤镜应该是…

<receiver
        android:name="com.myapp.push.ExternalReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.myapp.blablabla" />
        </intent-filter>
    </receiver>

最新更新