> shouldOverrideUrlLoading Webview Android

I need solved a problem with Webview and the method ShouldOverrideUrlLoading.

I want to display a message indicating that the user doesn't have the twitter app installed on your phone

    @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;

}

The error that show "The application has stopped unexpectedly. Please try again"

Can anyone help?


There seems to be a problem with your twitter Intent . As far as I understood you want the twitter app to post something. Consult their API's about how to launch twitter app using an Intent. To prevent crashes you might do the following:

 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;
链接地址: http://www.djcxy.com/p/41966.html

上一篇: 为什么只有在IE中打开开发人员工具后才能使用JavaScript?

下一篇: > shouldOverrideUrlLoading Webview Android