Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube API ActivityNotFoundException on Gingerbread

I am getting ActivityNotFoundException error when i am trying to run youtube api StandAlonePlayerActivity on ginger bread. Where as it runs fine on ICS

here is my log cat

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)

and here is the code which i have used for starting Player

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

I am getting error on startActivity

Here is getYoutubeVideoID() code :

/*
     * 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;
    }
like image 324
Manoj Avatar asked Jan 23 '13 10:01

Manoj


2 Answers

First check if the youtube service is available on your device, then try to launch that activity. YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mContext). Also try installing the youtube app from Google play.

Tiny note from the documentation: Note: Users need to run version 4.2.16 of the mobile YouTube app (or higher) to use the API.

Edit: This is how you use it:

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 :)  
}

See the YouTubeInitializationResult enums here https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeInitializationResult

Also the philosophy about the aforementioned class: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeApiServiceUtil

like image 61
Nikola Despotoski Avatar answered Nov 17 '22 00:11

Nikola Despotoski


The devices should have the latest YouTube app installed.

like image 44
tasomaniac Avatar answered Nov 17 '22 01:11

tasomaniac