生活随笔
收集整理的這篇文章主要介紹了
Android淘宝客链接自动跳转淘宝APP问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
項目中的是騰訊X5瀏覽器,發現淘寶客不能自動喚起淘寶APP,log后均是http/https請求,后來使用原生WebView,log發現淘寶客跳轉會有一個tbopen://開頭的地址,這才是真正喚起淘寶App的scheme地址。X5卻是拿不到,綜合考慮應該跟微信類似的屏蔽了外鏈的跳轉,而淘寶這種大型App自然在過濾清單中,所以X5瀏覽器中找不到類似的scheme,故而只能換用原生WebView。
方法:
在shouldOverrideUrlLoading方法中攔截url,匹配到tbopen://開頭的,做跳轉。以下為通用方法。關于原生WebView的配置與問題請看我的另一篇博客:Android 原生WebView訪問使用iFrame網頁問題
mWebView
.setWebViewClient(new WebViewClient() {@Overridepublic void onPageStarted(WebView view
, String url
, Bitmap favicon
) {super.onPageStarted(view
, url
, favicon
);}@Overridepublic void onReceivedSslError(WebView view
, SslErrorHandler handler
, SslError error
) {handler
.proceed();super.onReceivedSslError(view
, handler
, error
);}@Overridepublic boolean shouldOverrideUrlLoading(WebView view
, String url
) {try {if (!TextUtils
.isEmpty(url
)) {if (!url
.startsWith("http") && !url
.startsWith("https")) {try {final Intent intent
= Intent
.parseUri(url
, Intent
.URI_INTENT_SCHEME
);intent
.setFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
| Intent
.FLAG_ACTIVITY_SINGLE_TOP
);intent
.addCategory("android.intent.category.BROWSABLE");intent
.setComponent(null
);if (null
!= intent
) {startActivity(intent
);}return true;} catch (Exception e
) {e
.printStackTrace();ToastUitl
.showShort("尚未安裝此應用!");return true;}}}} catch (Exception e
) {e
.printStackTrace();}if (url
.contains("http") || url
.contains("https")) {view
.loadUrl(url
);return true;}return super.shouldOverrideUrlLoading(view
, url
);}@TargetApi(Build
.VERSION_CODES
.LOLLIPOP
)@Overridepublic WebResourceResponse
shouldInterceptRequest(WebView view
, WebResourceRequest request
) {return super.shouldInterceptRequest(view
, request
);}@Overridepublic void onPageFinished(WebView view
, String url
) {super.onPageFinished(view
, url
);if (null
!= title
&& null
!= view
&& TextUtils
.isEmpty(mTitle
))title
.setText(view
.getTitle());}});
總結
以上是生活随笔為你收集整理的Android淘宝客链接自动跳转淘宝APP问题的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。