Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.content.ActivityNotFoundException: passing url to the intent

I have the following error in my app:

Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://m.fretebras.com.br/fretes }
   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
   at android.app.Activity.startActivityForResult(Activity.java:3468)
   at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
   at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
   at android.app.Activity.startActivityForResult(Activity.java:3429)
   at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
   at android.app.Activity.startActivity(Activity.java:3671)
   at android.app.Activity.startActivity(Activity.java:3639)
   at br.lgfelicio.atividades.Checkin.acaoBotao(Checkin.java:773)
   at br.lgfelicio.atividades.Checkin$12.onClick(Checkin.java:312)
   at android.view.View.performClick(View.java:4461)
   at android.view.View$PerformClick.run(View.java:18543)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5118)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
   at dalvik.system.NativeStart.main(NativeStart.java)

Code with error:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.fretebras.com.br/fretes"));
startActivity(i);

The error occurs in versions 6.0.1 android, I have no idea why it's happening, I believe that by passing the url to Intent is all right. Can someone help me?

like image 926
ruitercomp Avatar asked Oct 26 '16 10:10

ruitercomp


1 Answers

Seems like no browser installed on your phone. Please verify and to avoid crash use below code.

try {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.fretebras.com.br/fretes"));
        startActivity(i);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }

Note - This code will just ignore your crash, if no browser found.

like image 91
Rahul Avatar answered Nov 12 '22 04:11

Rahul