Hi guys,I use signpost-oauth do oauth in android, and after login on the web page, return to the Activity, the provider is null sometimes.
public class LoginActivity extends Activity implements View.OnClickListener {
private static OAuthConsumer consumer;
private static OAuthProvider provider;
private static final Uri CALLBACK= Uri.parse("xxx://callback?");
...
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
final Uri uri = intent.getData();
if (uri != null && uri.toString().startsWith(CALLBACK)) {
final String pin = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
try {
//provider.setOAuth10a(true);
provider.retrieveAccessToken(consumer, pin);
} catch (final Exception e) {
}
}
}
...
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.oAuthLoginBtn:
new Thread(new Runnable() {
public void run() {
LoginActivity.consumer = new CommonsHttpOAuthConsumer(
apiKey, appSecret);
LoginActivity.provider = new CommonsHttpOAuthProvider(
oauthUrl + Data.REQUEST_TOKEN_URL, oauthUrl
+ Data.ACCESS_TOKEN_URL, oauthUrl
+ Data.AUTHORIZE_URL);
LoginActivity.provider.setOAuth10a(true);
try {
final String authUrl = LoginActivity.provider
.retrieveRequestToken(LoginActivity.consumer,
CALLBACK);
final Uri uri = Uri.parse(authUrl);
final Intent it = new Intent(Intent.ACTION_VIEW, uri);
LoginActivity.this.startActivity(it);
} catch (final Exception e) {
}
}
}).start();
break;
}
}
and the manifest.xml
<activity android:name=".ui.LoginActivity" android:label="@string/activity_login"
android:launchMode="singleInstance" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="xxx" />
</intent-filter>
</activity>
I don't know why the provider is null sometimes.