我需要解决一个问题与Webview和方法shouldoverrideurlloading。
我想显示一条消息,表明用户的手机上没有安装twitter应用程序
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("tel:")) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); startActivity(intent); }else if(url.startsWith("http:") || url.startsWith("https:")) { view.loadUrl(url); }else if (url != null && url.startsWith("market://")) { view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else if (url != null && url.startsWith("twitter://")) { view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; }else{ Toast.makeText(getApplicationContext(), "Twitter app is necessary", Toast.LENGTH_SHORT).show(); } return false;显示“应用程序意外停止,请重试”的错误
有人能帮忙吗?
您的twitterintent
似乎有问题。据我所知,你想让twitter应用发布一些东西。请参考他们的API,了解如何使用Intent启动twitter应用程序。为了防止崩溃,您可以执行以下操作:
else if (url != null && url.startsWith("twitter://")) {
try{
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch(ActivityNotFoundException e){
// do some stuff here, for example load the twitter url in the browser
}
return true;