在短信中點擊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。