I’m building an Android application that uses the Spotify SDK for music playback. Everything works great when I test it on the Android emulator - user authentication completes successfully and songs play without issues.
However, when I run the same code on my physical device, I get an INVALID_APP_ID error during the authentication process. The weird part is that if I completely remove the official Spotify app from my phone, then my application works perfectly on the device too.
It seems like there’s some conflict between my app and the installed Spotify client. Has anyone encountered this before? What’s the proper way to handle this situation?
Here’s my authentication handling code:
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
if (reqCode == AUTH_REQUEST_CODE) {
AuthenticationResponse authResponse = AuthenticationClient.getResponse(resCode, data);
if (authResponse.getType() == AuthenticationResponse.Type.TOKEN) {
Config config = new Config(this, authResponse.getAccessToken(), app_client_id);
accessToken = authResponse.getAccessToken();
Spotify.getPlayer(config, this, new Player.InitializationObserver() {
@Override
public void onInitialized(Player spotifyPlayer) {
musicPlayer = spotifyPlayer;
musicPlayer.addConnectionStateCallback(MainActivity.this);
musicPlayer.addPlayerNotificationCallback(MainActivity.this);
}
@Override
public void onError(Throwable error) {
Log.e("SpotifyAuth", "Player initialization failed: " + error.getMessage());
}
});
}
}
}