[英]How to sync firebase database while receiving push notification in android
[英]How to get data from notification when receiving push for android (firebase)?
我正在android上发送此类消息
{
"to": "dmi38iyVcvs:APA91bEDaB1jmhwZzRq-Sk448FuYItqMtJkAtzfJVr2ECNB-3I2HiBcadukMHsez7BxtbUEUHOddJzQccbNTgVu6Ay3QVqa3lEGhUqaT6rwee45x9sCtB_YVlxM9pl56ryahUU346Rw8",
"data": {
"title": "trtr",
"message": "trtr",
"deeplink": "https://webview/google.com"
}
}
并在FirebaseMessagingService中解析,但是在iOS中没有字段“ notification”的情况下推送不起作用(带有“ notification”字段都可以)
使用字段“通知”,我无法从Android上的推送获取数据
我正在阅读官方的停放基地,但找不到答案
这个解析数据
override fun onMessageReceived(remoteMessage: RemoteMessage) {
remoteMessage?.data?.let {
val bundle = Bundle()
bundle.putString(TITLE, it[TITLE])
bundle.putString(MESSAGE, it[MESSAGE])
bundle.putString(LINK, it[LINK])
createNotificationChannel()
sendNotification(bundle)
} ?: run {
Timber.v("received null")
return
}
}
然后我尝试同时离开通知字段和数据字段
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Object data = getIntent().getData() //Not working (data = null)
}
如何离开两个字段(通知和数据)并从android中的“日期”字段获取数据?
我很难更清楚地描述问题,因此我将回答您所有澄清的问题
再过一段时间我解决了这个问题
在我的Manifest.xlm中,我添加了这个
<intent-filter>
<action android:name="VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
(对于我的MainActivity)
在MainActivity中的onCreate方法中添加
Intent intent = getIntent();
Bundle data = intent.getExtras();
Uri deepLinkUri = null;
if (data.containsKey("deeplink"))
deepLinkUri = Uri.parse(intent.getExtras().getString("deeplink"));
和POST JSON
{
"to": "dmi38i.....yVVvs",
"data": {
"deeplink": "app://webview/google.com"
},
"notification": {
"title": "test_notification",
"body": "test_notification",
"click_action" : "VIEW"
},
"priority": "high"
}
(在notification
添加了"click_action" : "VIEW"
)
我希望这可以帮助别人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.