DeepLink Android


浏览:911 次

当使用导航组件时,我们肯定会接触到导航的DeepLink。中文名称是深层联系。本文分享了DeepLink的知识,希望对阅读本文的人有所启发。

DeepLink应用场景

PendingIntent:当app收到通知推送时使用此方法。我们希望用户单击通知以跳转到显示通知内容的界面。

URL:当用户使用移动浏览器网站上的界面时,他们可以在网页上使用类似于“在app中打开”的按钮。如果用户的手机安装了app,我们可以通过DeepLink打开相应的界面。如果没有安装,可以跳转到app的下载界面,指导用户安装app。

PendingIntent的使用

场景:想象一下通知栏中的通知。单击可跳转以显示通知的详细信息。

;private fun sendNotification(){

 nbsp; ;val生成器:NotificationCompat。Builder=通知Compat.Builder(此为“CHANNEL_ID”)

 nbsp; ; ; 。setSmallIcon(R.mipmap.ic_launcher_round)

 nbsp; ; ; 。setContentTitle(“DeepLinkDemo”)

 nbsp; ; ; 。setContentText(“Hello World!”)

 nbsp; ; ; 。setPriority(NotificationCompat.PRIORITY_DEFAULT)

 nbsp; ; ; 。setContentIntent(getPendingIntent())

 nbsp; ; ; 。setAutoCancel(true)

}

;私人乐趣getPendingIntent():PendingInten{

 nbsp; ;val bundle=捆绑()

 nbsp; ;bundle.putString(“params”,“PendingIntent”)

 nbsp; ;return Navigation.findNavController(this,R.id.sendNotification)

 nbsp; ; ; 。创建深度链接()

 nbsp; ; ; 。setGraph(R.navigation.nav_graph)

 nbsp; ; ; 。setDestination(R.id.mainFragment)

 nbsp; ; ; 。setArguments(捆绑包)

 nbsp; ; ; 。创建PendingIntent()

}

上面的代码是为通知设置PendingIntent,然后我们在PendingInten中设置目标。如果您想自己设置状态栏通知,可以尝试此方法。

URL的使用

1.在导航地图<deepLink/>中的页面上,用相应的网页地址填写app:uri,参数可以通过Bundle对象传入。代码示例:

2.为活动设置<;导航图形/>标签。代码示例:

 nbsp;&书信电报;导航图形android:value=“@navigation/graph _ deep_link”/>;

相关资讯:
农产品电子商务向企业个人农产品电子贸易方向发展的效益

农产品电子商务向企业个人农产品电子贸易方向发展的效益

查看
Web 3.0技术的基本方向

Web 3.0技术的基本方向

查看
认知

认知

查看
面向对象的

面向对象的

查看
2018-12-25

2018-12-25

查看