gpt4 book ai didi

Android GCM 通知返回堆栈

转载 作者:行者123 更新时间:2023-11-29 01:23:10 25 4
gpt4 key购买 nike

我在 Android 上设置了 GCM,并且能够正确接收通知。在通知中,我设置了“click_action”,以便 android 在选择通知时为我打开一个特定的 Activity (ListActivity)。这一切都很好。

但是,如果用户通过按返回键离开应用程序,则当新 Activity 启动时(通过 gcm)整个返回堆栈都将丢失。这是我的 android list ,也是我如何发送通知的示例。

AndriodManifest.xml

<activity
android:name=".views.HomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity
android:name=".views.ListActivity"
android:parentActivityName=".views.HomeActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="OPEN_ACTIVITY_LIST"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".views.HomeActivity"/>
</activity>

通知示例

curl -X POST https://gcm-http.googleapis.com/gcm/send \
-H "Content-Type:application/json" \
-H "Authorization:key=AUTHORIZATION_KEY" \
-d '{
"to" : "GCM_TOKEN",
"priority" : "high",
"notification" : {
"body" : "Notification body",
"title" : "Notification Title",
"click_action": "OPEN_ACTIVITY_LIST"
},
"data": {
"message": "Please open an activity with a backstack configured!"
}
}'

是否可以让 gcm 自动为我创建返回堆栈?如果是这样,我该如何实现?

最佳答案

我发现这很有趣 website .看看Step 5 .我想这就是您要找的。

To allow a cloud message to open the app and jump straight to an Intercom message we need to get the intent data sent to us. In your apps launch activity (the first activity it will go to) add the following. You should call this method early in the Activity life-cycle such as onCreate.

Intercom.client().openGCMMessage(getIntent());

If you wish to create a custom back stack for this notification you can pass a TaskStackBuilder to the same method:

openGCMMessage(Intent intent, TaskStackBuilder stackBuilder);

关于Android GCM 通知返回堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35588109/

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