我想在我的应用中显示GCM推送通知的数据。 我在没有任何框架的情况下进行本地编程。
当用户点击推送通知时,如何启动特定功能? [我的应用程序刚刚打开,如果我点击通知]
如何获取推送通知的JSON数据?
我一直在寻找地狱,但大多数回复都是针对使用某种框架的用户。
提前致谢。
答案 0 :(得分:0)
在代码中查找IntentService,它可能与此类似,
这应该是您感兴趣的JSON。您可以采取任何您想要的操作,添加通知,创建弹出窗口等。
Log.i(TAG,“收到:”+ extras.toString());
public class GcmIntentService extends IntentService {
String TAG = "GcmIntentService";
public GcmIntentService(String name) {
super(name);
}
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()) {
if (GoogleCloudMessaging. MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
Log.i(TAG, extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
Log.i(TAG, extras.toString());
} else if (GoogleCloudMessaging. MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
}