android - 加载 YouTube 视频时出现 ActivityNotFoundException

标签 android exception

我使用此代码在支持它的 Activity (通常是浏览器)中加载 YouTube 视频:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + videoId));
context.startActivity(i);

我收到了这个匿名跟踪记录,我不知道这是怎么发生的。这是否意味着设备不知道它需要使用什么 Activity 来处理“http”协议(protocol)? (即没有浏览器?)

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://www.youtube.com/watch?v=xxxxxx }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
at android.app.Activity.startActivityForResult(Activity.java:3190)
at android.app.Activity.startActivity(Activity.java:3297)
at com.sprogcoder.basetube.d.c.a(Unknown Source)
at com.sprogcoder.basetube.f.b.onItemClick(Unknown Source)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.Gallery.onSingleTapUp(Gallery.java:960)
at android.view.GestureDetector.onTouchEvent(GestureDetector.java:568)
at android.widget.Gallery.onTouchEvent(Gallery.java:937)
at android.view.View.dispatchTouchEvent(View.java:5546)

谢谢!

最佳答案

如果您添加有效的视频 ID 会怎样?像“AOsgv_X_cV8”

String videoId = "AOsgv_X_cV8";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + videoId));
context.startActivity(i);

但我认为您正在尝试在模拟器上执行此操作,这就是您收到此错误消息的原因。 使用 youtube 应用。

try {   
url="vnd.youtube:"+videoId;
 context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch(ActivityNotFoundExcepiton e) {
   Toast.makeText(context, "Plase install Youtube app to see this video", Toast.LENGTH_LONG).show();
}

关于android - 加载 YouTube 视频时出现 ActivityNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11767172/

相关文章:

iOS 递归动画异常

java - Mockito 检查异常对此方法无效

c# - 设备和模拟器上的 UWP 异常

Android 在一个 ListView 中交换两个 itemView

java - 从布局中的所有编辑文本中获取文本 - Android 编程

android - 建立 Node.Js 本地服务器(localhost : 8888) on WiFi though WiFi Router (Passing it through LAN to WiFi Router)?

java - 如何继承一个RuntimeException类?

android - 同一 Activity 上的两个抽屉导航

android - 比较 2 个 JSONObject

java - 错误: cannot find symbol for Exceptions in Java