webview 跨進程啓動

在Android端內,會稍微麻煩一些,在外部的m頁,會發起一個schema的僞協議鏈接,系統會去根據這個schema去檢索,需要被拉起的App需要有一個配置文件,大致如下:

<activity
 android:name=".activity.StartActivity"
 android:exported="true">
 <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="zhuanzhuan"/>
 </intent-filter>
</activity>

以上面的代碼爲例,在上面配置中scheme爲zhuanzhuan,只要是 "zhuanzhuan://" 開頭的schema的鏈接都會調起配置該schema的Activity(類似上面代碼的 StartActivity),此Activity會對這個 schema url 做處理,例如:

public class StartActivity extends TempBaseActivity {
 Intent intent;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

        intent = getIntent();
 Uri uri = intent.getData();
    }
}

例如上面的代碼,可以在此Activity中,通過 intent 中的 getData 方法,獲取到傳入的schema的相關信息,如下圖:

這也是我們在第三方app內,可以調起自己app的原理。當然現在市場上一些app,爲了怕有流量流失,會對schema進行限制,只有plist白名單裏的schema才能對應拉起,否則會被直接過濾掉。比如我們的wx爸爸,開通白名單後,纔可以使用更多的jsApiList,通過schema的拉起就是其中之一,在此不做贅述…… :)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章