gpt4 book ai didi

android - GCM Intent.getExtras——如何仅显示特定数据?

转载 作者:行者123 更新时间:2023-12-02 13:33:44 24 4
gpt4 key购买 nike

正在开发支持 GCM 的应用程序,我可以接收消息。但是格式显示为 Message: Bundle[{message=test, android.support.content.wakelock=3,collapse_key=do_not_collapes,from=3423423}]

如何指定仅显示消息数据 key 对?

GCM收到消息 Intent

 protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);

if (!extras.isEmpty()) { // has effect of unparcelling Bundle
/*
* Filter messages based on message type. Since it is likely that GCM will be
* extended in the future with new message types, just ignore any message types you're
* not interested in, or that you don't recognize.
*/
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " + extras.toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
for (int i = 0; i < 5; i++) {
Log.i(TAG, "Working... " + (i + 1)
+ "/5 @ " + SystemClock.elapsedRealtime());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
// Post notification of received message.
sendNotification("Message: " + extras.toString());
Log.i(TAG, "Message: " + extras.toString());
}
}
// Release the wake lock provided by the WakefulBroadcastReceiver.
GcmBroadcastReceiver.completeWakefulIntent(intent);
}

最佳答案

extras 是一个BundleBundle is a Java class ,使用方法 like getString()用于通过键访问各个数据 fragment ,非常类似于 HashMap。如果您只需要消息,请在extras上调用getString("message")

关于android - GCM Intent.getExtras——如何仅显示特定数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19027867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com