我正在开发一个带有的Android应用程序webView.在某些urls我需要使用这个shouldOverrideUrlLoading方法,这是非常直接的:
if(url.startsWith("something")){
//do something
return true;
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
URLS例如,谷歌搜索中的一些有以下URL方案:
intent://en.m.wikipedia.org/wiki/Test_cricket#Intent;scheme=http;package=org.wikipedia;S.browser_fallback_url=https%3A%2F%2Fwww.google.pt%2Fsearchurl%2Fr.html%23app%3Dorg.wikipedia%26pingbase%3Dhttps%3A%2F%2Fwww.google.pt%2F%26url%3Dhttps%3A%2F%2Fen.m.wikipedia.org%2Fwiki%2FTest_cricket;S.android.intent.extra.REFERRER_NAME=https%3A%2F%2Fwww.google.pt;launchFlags=0x8080000;end
Run Code Online (Sandbox Code Playgroud)
我尝试过使用:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误:
10-15 15:18:15.546: W/System.err(29086): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=intent://en.m.wikipedia.org/wiki/Test_cricket }
Run Code Online (Sandbox Code Playgroud)
我该如何处理这种URL方案?
更新:
在@CommonsWare评论之后,我尝试使用parseUri()on Intent来创建一个Intent objectfrom URL然后尝试startActivity(),例如:
Intent myIntent = new Intent().parseUri(url, Intent.URI_INTENT_SCHEME);
startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)
但我仍然得到:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://en.m.wikipedia.org/wiki/Test_cricket flg=0x8080000 pkg=org.wikipedia (has extras) …Run Code Online (Sandbox Code Playgroud)