Announcements

Help Wizard

Step 1

NEXT STEP

Android SDK Auth window not popping up

Android SDK Auth window not popping up

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. 

Reply
1 Reply

Tail-wagging hello to you esauerbo!
To integrate the Spotify playback SDK into your Android app, you've followed tutorials but encountered an issue where the login window doesn't appear on the emulator. Here are some suggestions to address the problem:

  • Ensure that the Spotify app is installed on the emulator, as the SDK requires it for authentication.
  • Verify that the CLIENT_ID and REDIRECT_URI values in your code are correct and match your Spotify Developer Dashboard registration.
  • Double-check the redirect URI setup in the Spotify Developer Dashboard to ensure it matches your app's configuration.
  • Consider that the SDK's authentication flow may require a browser, which the emulator might lack. Test the login functionality on a physical Android device with the Spotify app installed to see if the issue persists.
  • Consult the Spotify Android SDK documentation and community forums for version-specific troubleshooting steps or reported issues.
  • Handle the CouldNotFindSpotifyApp error by informing the user that the Spotify app is required for authentication and providing installation instructions.

Following these suggestions should help you resolve the issue and display the Spotify login window successfully in your Android app.
I'll be doggone if I don't hear from you,

 

-Prague the Dog

PragueRising Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts