Last week I published app, this app contained just video links that allows the users to watch clips whenever they click any button link.
I am using this code to play video:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4");
view.getContext().startActivity(intent);
However, in some cases this code doesn’t work in several devices, some users of my app said it force closes the entire app whenever they press any link. I actually tried it on my Droid X, it worked perfectly fine.
Is there anything I am doing wrong? Please help me, I would really appreciate it a lot.
Here is the error I am getting.
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW
dat=http://www.yourvideos.mp4 typ=video/mp4 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
at android.app.Activity.startActivityForResult(Activity.java:2817)
at android.app.Activity.startActivity(Activity.java:2923)
at com.MyApplication.desc182$1.onClick(desc182.java:34)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
I had the exact same problem and never found a good reason why this happens. I ended up just catching ActivityNotFoundException and showing a dialog.
Here’s a way you can tell if there’s an activity that can handle a particular intent:
You can use this approach to see if the intent can be handled, and then message the user appropriately if there is no activity that can handle a particular intent.