Android 打开youtube链接时应用程序崩溃

Android 打开youtube链接时应用程序崩溃,android,youtube,Android,Youtube,我正在使用此代码打开youtube链接,它以前可以工作,但现在崩溃了 Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setClassName("com.google.android.youtube", "com.google.android.youtube.PlayerActi

我正在使用此代码打开youtube链接,它以前可以工作,但现在崩溃了

Intent intent= new Intent(Intent.ACTION_VIEW,
                        Uri.parse(url));
                intent.setClassName("com.google.android.youtube",
                        "com.google.android.youtube.PlayerActivity");
这是logcat

    STACK_TRACE=android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.youtube/com.google.android.youtube.WatchActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1636)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1430)
at android.app.Activity.startActivityForResult(Activity.java:3532)
at android.app.Activity.startActivityForResult(Activity.java:3493)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:840)
at android.app.Activity.startActivity(Activity.java:3735)
at android.app.Activity.startActivity(Activity.java:3703)
at com.scutify.CompanyDetailActivity.onItemClick(CompanyDetailActivity.java:366)
at android.widget.AdapterView.performItemClick(AdapterView.java:308)
at android.widget.AbsListView.performItemClick(AbsListView.java:1524)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3531)
at android.widget.AbsListView$3.run(AbsListView.java:4898)
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:5579)
你能告诉我为什么它会崩溃吗? 如何修复它? 谢谢

试试这段代码

Intent videoClient = new Intent(Intent.ACTION_VIEW);
videoClient.setData("VALID YOUTUBE LINK WITH HTTP");
videoClient.setClassName("com.google.android.youtube","com.google.android.youtube.WatchActivity");
startActivity(videoClient);
试试这个代码

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
startActivity(intent);
id是url中问号后面的标识符。例如:youtube.com/watch?v=ID


你能发布你的日志或任何可能有助于说明坠机原因的信息吗?如果没有这些信息,很难判断发生了什么……你的意图是否有两个名字(
intent
tab5Intent
)?@CodeMonkey@Gaetan(对不起,我不能标记你):我已经更新了我的问题,你可以尝试
新的意图(intent.ACTION\u视图,Uri.parse(“vnd.youtube:+videoId))
如果你有视频的id,或者
新的意图(Intent.ACTION_VIEW,Uri.parse(youtubeur))
如果你有完整链接。@Gaëtan:我有完整链接,想直接打开Youtube。。。你们能帮忙吗???你们是在模拟器上测试还是在设备上测试?
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setData(url);
videoIntent.setClassName("com.google.anddroid.youtube","com.google.android.youtube.WatchActivity");
startActivity(videoIntent);