Android笔记

Deep Link( H5页面打开App)详解

2017-03-12  本文已影响0人  夕阳骑士

在我们实际开发过程中,会有这么一种需求:很多App都会有一个分享功能,也许是分享某个商品,或者是分享某一个帖子等,当我们分享给别人的时候,如果别人手机上安装有我们的App我们更希望别人点击分享链接之后能直接打开App更快的进行购买或者互动。

在安卓系统中,google给我买提供了一种叫做Deep Link的东西,可以为我们解决这个问题。

Deep Link本质是是一种自定义协议,我们可以按照http协议的方式来进行定义。

      <intent-filter>
              <action android:name="android.intent.action.VIEW"/>
              <category android:name="android.intent.category.DEFAULT"/>
              <category android:name="android.intent.category.BROWSABLE"/>
              <data android:scheme="demo" android:host="test" android:path="/detail"/>
      </intent-filter>
      <a href="demo://test/detail?key=value">打开App</a>
        Intent data=getIntent();
        Uri uri=data.getData();
        String scheme=uri.getScheme(); // demo
        String host=uri.getHost();     // test
        String path=uri.getPath();     // /detail
        String value=uri.getQueryParameter("key"); //value
上一篇 下一篇

猜你喜欢

热点阅读