如何在 PubNub Android 中接收推送通知???
How to receive a push notification in PubNub Android ???
在 pubnub 中接收推送通知的广播接收器是什么 android。
PubNub 发布了一篇博客 post,其中全面介绍了使用其 Android SDK 发送和接收 GCM。
Sending and Receiving Android Push Notifications w/ GCM
总而言之,接收器和 Intent 过滤器应如下所示:
<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 相关的任何内容!
在 pubnub 中接收推送通知的广播接收器是什么 android。
PubNub 发布了一篇博客 post,其中全面介绍了使用其 Android SDK 发送和接收 GCM。
Sending and Receiving Android Push Notifications w/ GCM
总而言之,接收器和 Intent 过滤器应如下所示:
<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 相关的任何内容!