forked from andrewtgomez96/StudyRecord
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotifyAuthenticationActivity.java
More file actions
62 lines (52 loc) · 2.33 KB
/
spotifyAuthenticationActivity.java
File metadata and controls
62 lines (52 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.example.spotifyapp2;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.spotify.sdk.android.authentication.AuthenticationClient;
import com.spotify.sdk.android.authentication.AuthenticationRequest;
import com.spotify.sdk.android.authentication.AuthenticationResponse;
import android.content.Intent;
public class spotifyAuthenticationActivity extends AppCompatActivity {
private String CLIENT_ID = "1f675cc0632f4dac87e247ed3e198f2b";
private String REDIRECT_URI = "http://com.yourdomain.yourapp/callback";
private static final int REQUEST_CODE = 1234;
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.com_spotify_sdk_login_activity);
AuthenticationRequest.Builder authreq = new AuthenticationRequest.Builder(
CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI
);
authreq.setScopes(new String[]{"Streaming"});
AuthenticationRequest request = authreq.build();
AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);
}
@Override
public void finish(){
super.finish();
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
// Check if result comes from the correct activity
if (requestCode == REQUEST_CODE) {
AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
switch (response.getType()) {
// Response was successful and contains auth token
case TOKEN:
Log.d("Authentication: ","Logged In.");
// Handle successful response
break;
// Auth flow returned an error
case ERROR:
Log.d("Authentication: ","Error.");
// Handle error response
break;
// Most likely auth flow was cancelled
default:
// Handle other cases
}
}
}
}