姜饼上的Youtube API ActivityNotFoundException

时间:2013-01-23 10:10:03

标签: android youtube-api

当我尝试在姜面包上运行youtube api StandAlonePlayerActivity时,我收到ActivityNotFoundException错误。在ICS上正常运行的地方

这是我的日志猫

01-23 15:34:28.071: E/AndroidRuntime(3378): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.youtube.api.StandalonePlayerActivity.START (has extras) }
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.Activity.startActivityForResult(Activity.java:2988)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:701)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.support.v4.app.Fragment.startActivity(Fragment.java:787)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at com.example.demo.TipsFragment$2.onClick(TipsFragment.java:143)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.view.View.performClick(View.java:2533)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.view.View$PerformClick.run(View.java:9320)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.os.Handler.handleCallback(Handler.java:587)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.os.Looper.loop(Looper.java:150)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at android.app.ActivityThread.main(ActivityThread.java:4389)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at java.lang.reflect.Method.invoke(Method.java:507)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
01-23 15:34:28.071: E/AndroidRuntime(3378):     at dalvik.system.NativeStart.main(Native Method)

这是我用来启动播放器的代码

String vid=getYoutubeVideoId(vlink);
Intent intent=YouTubeStandalonePlayer.createVideoIntent(getActivity(),DEVELOPER_KEY, vid, 0,true,false);
startActivity(intent);

我在startActivity

上收到错误

这是getYoutubeVideoID()代码:

/*
     * Getting id of video from url
     */
    public static String getYoutubeVideoId(String youtubeUrl)
    {
        String video_id="";
        if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http"))
        {

            String expression = "^.*((youtu.be"+ "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
            CharSequence input = youtubeUrl;
            Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
            Matcher matcher = pattern.matcher(input);
            if (matcher.matches())
            {
                String groupIndex1 = matcher.group(7);
                if(groupIndex1!=null && groupIndex1.length()==11)
                    video_id = groupIndex1;
            }
        }
        return video_id;
    }

6 个答案:

答案 0 :(得分:17)

首先检查您的设备上是否有可用的youtube服务,然后尝试启动该活动。 YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mContext)。另请尝试从Google Play安装youtube应用。

文档中的小记: Note: Users need to run version 4.2.16 of the mobile YouTube app (or higher) to use the API.

编辑:这是您使用它的方式:

if(YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mContext).equals(YouTubeInitializationResult.SUCCESS)){
   //This means that your device has the Youtube API Service (the app) and you are safe to launch it. 

}else{
   // Log the outcome, take necessary measure, like playing the video in webview :)  
}

请参阅此处的YouTubeInitializationResult枚举https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeInitializationResult

关于上述课程的哲学: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeApiServiceUtil

答案 1 :(得分:1)

设备应安装最新的YouTube应用程序。

答案 2 :(得分:0)

您是否在模拟器上运行应用程序?它可能无法在模拟器上运行,因为默认情况下未安装youtube播放器。尝试在实际设备上运行它。

答案 3 :(得分:0)

为了在Android上使用YouTube api,您需要3个参数

1)YouTube Developer Key

2)视频ID

3)最新官方YouTube Android App(版本4.2.16)

通过查看你的日志猫,我认为其中一个缺失

Refer

答案 4 :(得分:0)

您必须在自己的设备上安装YouTube Android应用,这对我有用!

答案 5 :(得分:0)

我建议对@Nikola答案进行一些改进。可以显示本地化对话框getErrorDialog()来处理一些用户可恢复的错误isUserRecoverableError。例如,在“设置”中禁用YouTube应用时。

$num4 = count($_FILES['attach_doc']['name']);

    for($k = 0; $k < $num4; $k++) {

      $fname = pathinfo($_FILES['attach_doc']['name'][$k], PATHINFO_FILENAME); // Returns Filename without extention
      $exn = pathinfo($_FILES['attach_doc']['name'][$k], PATHINFO_EXTENSION); // Returns extention without Filename
      $docs = $fname.'-'.date("dmY").$k.'.'.$exn;

$intd = move_uploaded_file($_FILES["attach_doc"]["tmp_name"][$k], 'uploads/dev_req/attachment/'.$docs);


     $sql4 = mysqli_query($con, "INSERT INTO `erpdev_supporting_document` (`unique_id`, `supporting_doc`, `status`) VALUES ('$uid', '$docs', '1')");

     $msg = "<p style='color:#1578a5;'><strong>Request data has been added successfully</strong></p>";
    }