做外貿(mào)的數(shù)據(jù)網(wǎng)站鏈接檢測(cè)工具
對(duì)于googlePlay的Custom URL
就是googlePlay上APP網(wǎng)址:
https://play.google.com/store/apps/details?id=com.yourapp
如果是國(guó)內(nèi)一些應(yīng)用,則考慮market://
包名等方式,自行百度。
對(duì)于Android URI Scheme
:
首先需要在Manifest xml中定義:
<activityandroid:name="com.your.SplashActivity"...><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><!-- 必須分開(kāi)。 --><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="myapp" android:host="app"/></intent-filter></activity>
值得一提的是,作為啟動(dòng)應(yīng)用,你必須分割開(kāi)兩個(gè)intent-filter,否則就會(huì)導(dǎo)致應(yīng)用icon不見(jiàn)。而且BROWSABLE必須保證action和2個(gè)category。
測(cè)試方法
1. 寫(xiě)代碼:
startActivity(Intent(Intent.ACTION_VIEW,Uri.parse("myapp://app")).also { it.flags = it.flags or Intent.FLAG_ACTIVITY_NEW_TASK })
2. adb命令:
adb shell am start -W -d "myapp://app"
3. webView支持:
html中添加:
<a href="myapp://app">跳轉(zhuǎn)至MyApp</a>
對(duì)于真實(shí)的前端配置好以后,使用標(biāo)準(zhǔn)的瀏覽器去打開(kāi),是不會(huì)有問(wèn)題的。
因?yàn)樗隙▽?shí)現(xiàn)了類似下面的代碼。
自定義WebView中,點(diǎn)擊網(wǎng)頁(yè)中鏈接進(jìn)行跳轉(zhuǎn),出現(xiàn)err_unknown_url_scheme。
解決辦法,給WebViewClient添加如下代碼:
public boolean shouldOverrideUrlLoading(WebView view, String url) {boolean schemeUri = true; //可以額外定制代碼,進(jìn)行判斷return schemeUri && this.overrideUrlLoadUrl(view, url) ? true : super.shouldOverrideUrlLoading(view, url);
}public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {String uri = request.getUrl().toString();boolean schemeUri = true; //可以額外定制代碼,進(jìn)行判斷return schemeUri && !uri.isEmpty() && this.overrideUrlLoadUrl(view, uri) ? true : super.shouldOverrideUrlLoading(view, request);
}private boolean overrideUrlLoadUrl(WebView view, @NonNull String url) {if (!url.contains("http://") && !url.contains("https://")) {startActivity(view, url);return true;} else {view.loadUrl(url);return false;}
}static void startActivity(WebView view, @NonNull String url) {startActivity(view, Uri.parse(url));
}static void startActivity(WebView view, @NonNull Uri uri) {Intent intent = new Intent("android.intent.action.VIEW", uri);try {view.getContext().startActivity(intent);} catch (Exception var6) {intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);try {view.getContext().startActivity(intent);} catch (Exception var5) {Exception e2 = var5;e2.printStackTrace();}}}
參考:
https://developer.android.com/training/app-links/deep-linking?hl=zh-cn