YouTube Api for android exception "service_missing"
Asked Answered
B

2

27

I want to play you tube video in my android application

I got exception while youtube initialization like "service_missing".

I write following code,

package com.example.youtubedemo;
import android.os.Bundle;

import android.view.Menu;
import android.widget.Toast;
import com.google.android.youtube.player.*;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;

public class MainActivity extends YouTubeBaseActivity implements OnInitializedListener{

    static private final String DEVELOPER_KEY = "MY API KEY";

    static private final String VIDEO = https://www.youtube.com/watch?v=d6XXgeAkBfQ&list=PLWz5rJ2EKKc9Wam5jE-9oY8l6RpeAx-XM";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        YouTubePlayerView youTubeView = (YouTubePlayerView)
                findViewById(R.id.youtube_view);
        youTubeView.initialize(DEVELOPER_KEY, MainActivity.this);
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



    @Override
    public void onInitializationFailure(Provider arg0,YouTubeInitializationResult error) {
        Toast.makeText(this, "Oh no! "+error.toString(),Toast.LENGTH_LONG).show();

        Toast.makeText(this, ""+YouTubeInitializationResult.SERVICE_MISSING,Toast.LENGTH_LONG).show();
    }



    @Override
    public void onInitializationSuccess(Provider arg0, YouTubePlayer player,
            boolean arg2) {
        player.loadVideo(VIDEO);

    }

}

I had also given INTERNET users permission.

I test this code in 4.2.2 With google API AVD.

android:minSdkVersion="8"

android:targetSdkVersion="17"

Any one have any idea??

thanks in advance...

Bilicki answered 6/8, 2013 at 18:43 Comment(0)
P
31

As the API documentation for the Youtube API states:

YouTubeInitializationResult.SERVICE_MISSING
The YouTube API service is missing on this device.

You'll need to install the Youtube app into the emulator to make it work.

Policewoman answered 6/8, 2013 at 18:51 Comment(5)
You can use something like Genymotion as an emulator with Google Play Services installed which allows you to get the Youtube application.Ravelin
On Android 11 (30) API I have YouTube app installed but still the same issue, prior 30 API everything works fineIntercross
#64632393Intercross
@Intercross page not foundElm
there are package visibility restrictions from android 11 and onwards, add the below code in your manifest file: <queries> <intent> <action android:name="com.google.android.youtube.api.service.START" /> </intent> </queries> referene: medium.com/androiddevelopers/…Biblical
C
52

The issue with Android 11 is the os is restricting access to other apps. https://developer.android.com/training/basics/intents/package-visibility

Add the following to manifest tag in AndroidManifest to fix YouTube issue:

<queries>
   <intent>
     <action android:name="com.google.android.youtube.api.service.START" />
   </intent>
</queries>
Counterproductive answered 30/11, 2020 at 8:57 Comment(4)
Updating this query is not working. YouTubeInitializationResult.SERVICE_INVALIDColb
You should also check for YouTube App be installed on the device.Counterproductive
@ZahraJamshidi Any Specific version of the youtube app?Elm
According to their documentation: "Users need to run version 4.2.16 of the mobile YouTube app (or higher) to use the API." REF: developers.google.com/youtube/android/playerCounterproductive
P
31

As the API documentation for the Youtube API states:

YouTubeInitializationResult.SERVICE_MISSING
The YouTube API service is missing on this device.

You'll need to install the Youtube app into the emulator to make it work.

Policewoman answered 6/8, 2013 at 18:51 Comment(5)
You can use something like Genymotion as an emulator with Google Play Services installed which allows you to get the Youtube application.Ravelin
On Android 11 (30) API I have YouTube app installed but still the same issue, prior 30 API everything works fineIntercross
#64632393Intercross
@Intercross page not foundElm
there are package visibility restrictions from android 11 and onwards, add the below code in your manifest file: <queries> <intent> <action android:name="com.google.android.youtube.api.service.START" /> </intent> </queries> referene: medium.com/androiddevelopers/…Biblical

© 2022 - 2024 — McMap. All rights reserved.