Youtube API ActivityNotFoundException on Gingerbread

前端 未结 6 1901
悲&欢浪女
悲&欢浪女 2021-01-12 14:20

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

相关标签:
6条回答
  • 2021-01-12 14:50

    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

    0 讨论(0)
  • 2021-01-12 14:54

    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

    0 讨论(0)
  • 2021-01-12 14:54

    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!")
    }
    
    0 讨论(0)
  • 2021-01-12 14:57

    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.

    0 讨论(0)
  • 2021-01-12 15:05

    you have to install YouTube Android App on your device, it's worked for me !

    0 讨论(0)
  • 2021-01-12 15:08

    The devices should have the latest YouTube app installed.

    0 讨论(0)
提交回复
热议问题