gpt4 book ai didi

android - Android 异常 "service_missing"的 YouTube Api

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:55:56 26 4
gpt4 key购买 nike

我想在我的 android 应用程序中播放你管视频

我在 youtube 初始化时遇到异常,如“service_missing”。

我写了下面的代码,

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"

有人知道吗??

提前致谢...

最佳答案

Android 11 的问题在于操作系统限制了对其他应用的访问。 https://developer.android.com/training/basics/intents/package-visibility

将以下内容添加到 AndroidManifest 中的 list 标签以修复 YouTube 问题:

<queries>
<intent>
<action android:name="com.google.android.youtube.api.service.START" />
</intent>
</queries>

关于android - Android 异常 "service_missing"的 YouTube Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18088082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com