'im getting the `get youtuble app` dialog even if i have the leastest youtube app installed on my physical divice
im very new to youtube api when i test the app on my mobile phone a get youtube app dialog is showing even that i have the leastest vertion of the youtube app installed on my divice . i dont know where the error could be or what i did wrong .
import android.os.Build
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.youtube.player.YouTubeBaseActivity
import com.google.android.youtube.player.YouTubeInitializationResult
import com.google.android.youtube.player.YouTubePlayer
import com.google.android.youtube.player.YouTubePlayerView
const val KEY_VID_ID = "dQw4w9WgXcQ"
const val KEY_LIST_ID = "PLkNqPjK6mmFYDGUceKt73TmoM7srNpDlm"
class youtubePlayer : YouTubeBaseActivity(), YouTubePlayer.OnInitializedListener {
@RequiresApi(Build.VERSION_CODES.M)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val layout = layoutInflater.inflate(R.layout.activity_youtube_player,
null,
false) as ConstraintLayout
setContentView(layout)
val ytbView = YouTubePlayerView(this)
ytbView.layoutParams = ConstraintLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
layout.addView(ytbView)
ytbView.initialize(getString(R.string.KEY_API_ID ), this)
}
override fun onInitializationSuccess(
provider: YouTubePlayer.Provider?,
youtubePlayer: YouTubePlayer?,
wasRestored: Boolean,
) {
if(!wasRestored){
youtubePlayer?.cueVideo(KEY_VID_ID)
}
}
override fun onInitializationFailure(
provider: YouTubePlayer.Provider?,
errorType: YouTubeInitializationResult?,
) {
if(errorType!!.isUserRecoverableError()){
errorType.getErrorDialog(this , 0).show()
}else{
Toast.makeText(this, "an error accured ${errorType}", Toast.LENGTH_LONG).show()
}
}
}
'''
Solution 1:[1]
if you are using android 11 and apov you should add this code t o thye manefest
<intent>
<action android:name="com.google.android.youtube.api.service.START" />
</intent>
</queries>```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kamal douma |
