Android的视频意图问题 [英] Android Video Intent Problem

查看:95
本文介绍了Android的视频意图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上周,我发表的应用程序,这个应用程序只包含视频链接,允许用户在观看短片时,他们点击任何按钮链接。

我用这code播放视频:

 意向意图=新的意图(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(HTTP://www.yourvideo.mp4),视频/ MP4);
。view.getContext()startActivity(意向);
 

然而,在某些情况下,这code没有在多台设备的工作,我的应用程序的一些用户说,它的力量关闭时,他们preSS任何一个环节的整个应用程序。事实上,我试图在我的Droid X,它的工作完全正常。

有什么我做错了什么?请帮帮我,我真的AP preciate了很多。

下面是我得到的错误。

  android.content.ActivityNotFoundException:无活动处理意向{行动= android.intent.action.VIEW
    DAT = HTTP://www.yourvideos.mp4典型值=视频/ MP4}
    在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
    在android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
    在android.app.Activity.startActivityForResult(Activity.java:2817)
    在android.app.Activity.startActivity(Activity.java:2923)
    在com.MyApplication.desc182 $ 1.onClick(desc182.java:34)
    在android.view.View.performClick(View.java:2408)
    在android.view.View $ PerformClick.run(View.java:8816)
    在android.os.Handler.handleCallback(Handler.java:587)
    在android.os.Handler.dispatchMessage(Handler.java:92)
    在android.os.Looper.loop(Looper.java:123)
    在android.app.ActivityThread.main(ActivityThread.java:4627)
    在java.lang.reflect.Method.invokeNative(本机方法)
    在java.lang.reflect.Method.invoke(Method.java:521)
    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:878)
    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
    在dalvik.system.NativeStart.main(本机方法)
 

解决方案

我有完全相同的问题,并没有找到一个很好的理由,为什么出现这种情况

。最后我只是交谈ActivityNotFoundException并显示一个对话框。

下面是一个方式,你可以告诉我们,如果有,可以处理一个特定意图的活动:

 私人布尔checkCanOpenVideoMP4Url(字符串videoUrl){
    意向意图=新的意图(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(URL),视频/ MP4);

    名单< ResolveInfo> 。resolveInfo = getPackageManager()queryIntentActivities(意向,0);

    返回(resolveInfo.size()0);
}
 

您可以用这个方法来看看的意图可以被处理,然后消息的用户适当,如果没有活动,可以处理一个特定的意图。

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:

private boolean checkCanOpenVideoMP4Url(String videoUrl) {
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(Uri.parse(url), "video/mp4"); 

    List<ResolveInfo> resolveInfo = getPackageManager().queryIntentActivities(intent, 0);

    return (resolveInfo.size() > 0);
}

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.

这篇关于Android的视频意图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆