
我还在应用程序中实现了动态链接.
但是,我无法找到通过动态链接发送通知的方法(因此在点击通知时,会打开某个动态链接).我只能看到发送文本通知的选项.
有没有解决方法或这是FCM的限制?
解决方法 您必须使用自定义数据实现服务器端发送通知,因为当前控制台不支持它. (使用自定义键值对无法正常工作,因为当您的应用处于后台模式时,通知不会深层链接).在这里阅读更多: https://firebase.google.com/docs/cloud-messaging/server拥有自己的App Server后,可以将Deep link URL包含在通知的自定义数据部分中.
在FirebaseMessagingService实现中,您需要查看有效内容并从中获取URL,创建使用该深层链接URL的自定义意图.
我目前正在使用AirBnb的深层链接调度程序库(https://github.com/airbnb/DeepLinkDispatch),在这种情况下可以很好地工作,因为您可以设置数据和DeeplinkActivity的链接,并为您进行链接处理.在下面的示例中,我将有效负载从服务器转换为名为DeeplinkNotification的对象,其中包含一个URL字段.
private voID sendDeeplinkNotification(final DeeplinkNotification notification) { ... Intent mainIntent = new Intent(this,DeeplinkActivity.class); mainIntent.setAction(Intent.ACTION_VIEW); mainIntent.setData(Uri.parse(notification.getUrl())); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addNextIntent(mainIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(notificationID,PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = buildBasicNotification(notification); builder.setContentIntent(pendingIntent); notificationmanager.notify(notificationID,builder.build());} DeeplinkActivity:
@DeeplinkHandlerpublic class DeeplinkActivity extends AppCompatActivity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dispatch(); } private voID dispatch() { DeeplinkResult deeplinkResult = DeeplinkDelegate.dispatchFrom(this); if (!deeplinkResult.isSuccessful()) { Timber.i("Deep link unsuccessful: %s",deeplinkResult.error()); //do something here to handle links you don't kNow what to do with } finish(); }} 在执行此实现时,与仅使用任何URL设置Intent.ACTION_VIEW的意图相比,您也不会打开任何您无法处理的链接.
总结以上是内存溢出为你收集整理的android – 如何使用Firebase通知打开动态链接?全部内容,希望文章能够帮你解决android – 如何使用Firebase通知打开动态链接?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)