/
ReceiverActivity.java
49 lines (42 loc) · 1.56 KB
/
ReceiverActivity.java
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
package com.adi.awesomeapp;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
/**
* The sole purpose of this Activity is to be started
* and respond to the Intent when the browser redirects
* the user to the callback url. This Activity captures the intent
* thanks to the Intent Filter we added in the AndroidManifest.
* It extracts the oauth_verifier from the intent and authenticates the user.
*/
public class ReceiverActivity extends Activity {
private static final String TAG = "ReceiverActivity";
/**
* Handle Twitter callback after signing in
*/
@Override
public void onCreate(Bundle savedState)
{
super.onCreate(savedState);
onNewIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
Log.d(TAG, "Received intent");
super.onNewIntent(intent);
parseTwitterCallback(intent);
}
private void parseTwitterCallback(Intent intent) {
Uri uri = intent.getData();
final String CALLBACK_URL = this.getString(R.string.callback_url);
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
TwitterService.getInstance(this).authenticate(this, oauthVerifier);
}
Toast.makeText(this, "You're logged in! Try pressing 'Tweet' again.", Toast.LENGTH_LONG).show();
startActivity(new Intent(this, MainActivity.class));
}
}