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 l
In order to use YouTube api for android you need 3 Parameters
1) YouTube Developer Key
2)Video Id
3)Latest official YouTube Android App (version 4.2.16)
By looking on you log cat i think one among this is missing
Refer
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
I would suggest some improvements to @Nikola answer. It's possible to show localised dialog getErrorDialog() to handle some user-recoverable errors isUserRecoverableError. For example, when YouTube app is disabled in Settings.
val result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(context)
when {
result == YouTubeInitializationResult.SUCCESS -> startYouTubeActivity()
result.isUserRecoverableError -> result.getErrorDialog(activity, 0).show()
else -> toast("Something went wrong!")
}
Are you running the app on the emulator? It might not work on the emulator as youtube player is not installed by default. Try running it on an actual device.
you have to install YouTube Android App on your device, it's worked for me !
The devices should have the latest YouTube app installed.