版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lylddingHFFW/article/details/79248590
在短信中点击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。