我正在使用此代码打开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)
你能告诉我它崩溃的原因吗? 怎么解决? 感谢
答案 0 :(得分:0)
试试此代码
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);
答案 1 :(得分:0)
试试这段代码,
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);