【问题标题】:Application crashes when open youtube link打开 youtube 链接时应用程序崩溃
【发布时间】:2014-08-19 07:23:20
【问题描述】:

我正在使用此代码打开 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)

你能告诉我为什么会崩溃吗? 如何解决? 谢谢

【问题讨论】:

  • 您能否发布您的 logCat 或任何可能有助于显示崩溃原因的内容?如果没有这些信息,很难判断发生了什么......
  • 是否打算为您的意图设置两个名称(intenttab5Intent)?
  • @CodeMonkey @Gaetan(对不起,我无法标记你):我已经更新了我的问题
  • 如果你有视频的ID,你可以试试new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId)),如果你有完整的链接,你可以试试new Intent(Intent.ACTION_VIEW, Uri.parse(youtubeUrl))
  • @Gaëtan:我有完整链接,想直接打开 Youtube...你能帮忙吗????

标签: android youtube


【解决方案1】:

试试这个代码

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);

【讨论】:

    【解决方案2】:

    试试这个代码,

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
    startActivity(intent);
    

    id是url中问号后面的标识符。例如:youtube.com/watch?v=ID

    Intent videoIntent = new Intent(Intent.ACTION_VIEW);
    videoIntent.setData(url);
    videoIntent.setClassName("com.google.anddroid.youtube","com.google.android.youtube.WatchActivity");
    startActivity(videoIntent);
    

    【讨论】:

    • 你是在模拟器还是在设备中测试?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多