我制作webview应用程序。我想在默认视频播放器和播放商店中打开两个网址“rtsp://”和“market://”。 我用这个代码。但问题是“market://”url在Play商店中正确打开,但rtsp链接未在默认视频播放器中打开。错误说找不到页面。
public class MainActivity extends Activity {
//private Button button;
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
startWebView("http://google.com");
this.webView.setWebViewClient(new WebViewClient());
this.webView.setDownloadListener(new DownloadListener()
{
public void onDownloadStart(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3, String paramAnonymousString4, long paramAnonymousLong)
{
Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString1));
MainActivity.this.startActivity(localIntent);
}
});
this.webView.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString)
{
if (paramAnonymousString.startsWith("rtsp"))
{
Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString));
MainActivity.this.startActivity(localIntent);
return true;
}
return super.shouldOverrideUrlLoading(paramAnonymousWebView, paramAnonymousString);
}
});
this.webView.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getScheme().equals("market")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Activity host = (Activity) view.getContext();
host.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
// Google Play app is not installed, you may want to open the app store link
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}
});
}