美文网首页
通过短信和URL打开APP

通过短信和URL打开APP

作者: 我才是张雷 | 来源:发表于2017-04-03 12:57 被阅读0次

功能实现:

1.首先在manifest中目标Activity中添加

<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:host="xxx.xxx"
                android:pathPrefix="/xxx"
                android:scheme="xxx" />
</intent-filter>

上面的xxx填写,以“myapp://digo.com/app”为例

<data
      android:host="digo.com"
      android:pathPrefix="/app"
      android:scheme="myapp" />

2.如果想要在目标内获取传递的参数,比如“myapp://digo.com/app?id=xxx”(xxx为任意数)

    Intent intent = getIntent();
    String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        Uri uri = intent.getData();
        if (uri != null) {
            productId = uri.getQueryParameter("id");
        }
    } 

相关文章

网友评论

      本文标题:通过短信和URL打开APP

      本文链接:https://www.haomeiwen.com/subject/lkanottx.html