Android Studio 2022.2.1 Patch 2
United States
Pixel 4 API 33 Emulator
Kotlin
I've been working off of this and this to try to get Spotify playback SDK on my Android app (for authentication going with the first option, using the Spotify client as opposed to the browser).
My code is pretty much lifted exactly from the tutorials except for some changes I had to make to deprecated functions (replacing onActivityResult with registerForActivityResult etc) and it builds/initially runs with no errors.
private fun login() {
val builder = AuthorizationRequest.Builder(
CLIENT_ID,
AuthorizationResponse.Type.TOKEN,
REDIRECT_URI
)
builder.setScopes(arrayOf("streaming"))
val request: AuthorizationRequest = builder.build()
AuthorizationClient.openLoginActivity(this, REQUEST_CODE, request)
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
// Check if result comes from the correct activity
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
val resultCode = result.resultCode
val data = result.data
val response: AuthorizationResponse = AuthorizationClient.getResponse(resultCode, data)
when (response.type) {
// Response was successful and contains auth token
AuthorizationResponse.Type.TOKEN -> {
println("Success! ${AuthorizationResponse.Type.TOKEN}")
}
// Auth flow returned an error
AuthorizationResponse.Type.ERROR -> {
println("Error")
println(AuthorizationResponse.Type.ERROR)
}
// Most likely auth flow was cancelled
else -> {
println("Auth flow canceled")
}
}
} else {
println("No result returned")
}
}
}
The login function is triggered by the click of a button. My issue is when I click the button the emulator goes to the phone's home screen but doesn't open a browser (spotify isn't downloaded on the emulator) to log into Spotify. I then get errors from the onStart method saying that SpotifyAppRemote is not defined.
null
com.spotify.android.appremote.api.error.CouldNotFindSpotifyApp
I'm not sure if this more of a Spotify or Android issue but I was wondering if anyone had a similar issue where they were unable to get the login window to appear on Android and if you found a solution. I can provide more detail about the errors as well, not sure what would be useful.