1

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?

2
  • "The application has stopped unexpectedly" - this is shown to the user. Could you post some LogCat output? "Necessary" is spelled with double "s" by the way
    – Droidman
    Commented Aug 24, 2013 at 1:06
  • @Maver1ck Logcat : dropbox.com/s/8as0eu855wis884/screen1.png Commented Aug 24, 2013 at 1:18

1 Answer 1

1

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;
1
  • In fact you should have try/catches around all of your startActivity calls, not all devices have phone apps to handle tel: links. Unsure if all Android can handle market: scheme urls...
    – Russ
    Commented Apr 15, 2016 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.