在pubnub android中接收推送通知的广播接收器是什么。
答案 0 :(得分:1)
PubNub发布了一篇博文,内容完全涵盖了使用Android SDK发送和接收GCM。
Sending and Receiving Android Push Notifications w/ GCM
总而言之,接收器和意图过滤器应如下所示:
<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="your.package.name" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
你的GcmBroadcastReceiver
应该是这样的:
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
最后,GcmIntentService
:
public class GcmIntentService extends IntentService {
public GcmIntentService() {
super("GcmIntentService");
}
@Override protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty() && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE) {
sendNotification("Received: " + extras.toString());
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
...
}
如果有任何我想要查看的内容,请查看博客。如果你没有在那里看到它或者仍然有问题让我知道,我很乐意详细说明任何与你有关的PubNub GCM!