我正在使用某些服务器代码发送通知。我知道有不同的方法和技术来处理背景和前景通知。在两种情况下均能完美交付。但是一些额外的普通情况存在一些问题:
!)将带有数据的通知发送到设备。
2)从设备接收它并按照“ click_action”提及打开的活动将其打开。
这是Android清单中用于click_action
的代码:
<activity
android:name=".activity.VideoNotificationActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:excludeFromRecents="true"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:taskAffinity=""
android:theme="@style/AppTheme.DarkStatusBar">
<intent-filter>
<action android:name="VideoDetailsActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
因此,此活动已根据click_action : VideoDetailsActivity
以下是此类背景条件的获取数据代码:
val bundle = intent.extras
if (bundle != null) {
isNotification = true
mVideoData = Gson().fromJson(bundle.getString(Globals.videoObject), ModelVideoList::class.java) as ModelVideoList
}
获取视频数据后,即可成功播放视频。但是在某些情况下:
3)最小化应用程序(我不会从此屏幕上走到任何地方。只需触摸最小化应用程序按钮!)。
4)从服务器发送具有不同数据的第二条通知!并成功接收到它。
5)单击该通知并打开相同的屏幕,但数据是先前视频的数据(意味着我单击的第二条通知数据未获得,因此我正在获得先前通知的旧数据!)
那么,如果用户最小化打开的通知屏幕的应用程序,并收到使用相同的旧数据打开的具有不同数据的第二次通知,我该怎么办?!
这是我要发送的数据:
{
"title": "New video added!",
"body": "Tap here to see a video!",
"click_action": "VideoDetailsActivity",
"icon": "ic_notification",
"color": "#CD201F",
"tag": "video_of_the_day",
"sound": "sound.mp3",
"notification_type": "video_of_the_day",
"data": {
"id": 20,
"title": "abcd",
"video": "abcd.mp4",
"video_webm": "abcd.webm",
"height": 960,
"width": 540,
"thumbnail": "abcd.jpg",
"created": 4124,
"created_at": "2019-07-05 11:09:10",
"updated_at": "2019-12-13 07:17:18",
"video_url": "video_link",
"is_new": false
},
"android_channel_id": "Video"
}
答案 0 :(得分:0)
在生成通知时传递不同的通知ID