在短信中点击URL打开相应的App

在短信中点击URL打开相应的App的具体操作。
在AndroidManifest中指定的Activity中添加intent-filter,并不一定是程序入口(android.intent.action.MAIN)启动的Activity:

<intent-filter>
     ........
</intent-filter> 
<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="test.com"
          android:pathPrefix="/testApp"
          android:scheme="http" />
 </intent-filter>

在短信中的URL格式为:http://test.com/testApp即可。
若URL带参数:http://test.com/testApp?name=test,在指定Activity中可以获取链接URL传递的参数,并做相应的逻辑处理。如下:

Intent intent = getIntent();
String action = intent.getAction();
if (Intent.ACTION_VIEW.equals(action)) {
     Uri uri = intent.getData();
     if (uri != null) {
         String name = uri.getQueryParameter("name");
         Toast.makeText(this, "name=" + name ,Toast.LENGTH_SHORT).show();
     }
}

另外要注意Activity的启动模式和逻辑,如果要走onNewIntent,需要使用setIntent(intentOn)设置新的intent。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值