I have been trying to find out within 4 days why my application is not working as I expect.
My application wants to use OAuth with twitter (it works), and when calling it back, it should introduce the onNewIntent method. It does not, and I cannot understand why.
So clicking twitterbutton opens a web page where I can enter my credentials. Then I get a screen indicating that it was successful and that I will be redirected back to my application. I am returning to my application, but the onNewIntent method is never called. I put a breakpoint at the beginning of the onNewIntend method and started the debugger. This does not stop with this method! It stops in other methods, so it cannot be a debugger.
In my log file (included), in the third line below, you can see that it starts a new intention. So ... what's going on here?
Can someone explain? I am very confused.
This is my code that runs when the twitter button is clicked:
callBackURL = "myapp://twitactivity";
httpOauthConsumer = new CommonsHttpOAuthConsumer(consKey, consSec);
httpOauthProvider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token","http://twitter.com/oauth/access_token", "http://twitter.com/oauth/authorize");
String authUrl = httpOauthProvider.retrieveRequestToken(httpOauthConsumer, callBackURL);
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(authUrl)));
This is the initial code of my onNewIntent method:
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.i("onNewIntent", "Yep success.");
Uri uri = intent.getData();
if(uri != null && uri.toString().startsWith(callBackURL)) {
String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
etc......
My manifest file also has the following:
<activity android:name=".TwitterScreen">
<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="myapp" android:host="twitactivity" />
</intent-filter>
</activity>
And here is what I see in my log file:
01-24 10:23:36.064: INFO/ActivityManager(61): Displayed activity nl.gemoro.android.demo/.TwitterScreen: 6660 ms (total 6660 ms)
01-24 10:23:38.614: INFO/global(348): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
01-24 10:23:44.025: INFO/ActivityManager(61): Starting activity: Intent { act=android.intent.action.VIEW dat=http://twitter.com/oauth/authorize?oauth_token=KjCUNMKg13OClyRjQff94QWKfoRBUpNLE2uF9cJkHA cmp=com.android.browser/.BrowserActivity }
01-24 10:23:44.185: INFO/ActivityManager(61): Start proc com.android.browser for activity com.android.browser/.BrowserActivity: pid=355 uid=10034 gids={3003, 1015}
01-24 10:23:44.724: INFO/ActivityThread(355): Publishing provider browser: com.android.browser.BrowserProvider
01-24 10:23:46.704: INFO/ActivityManager(61): Displayed activity com.android.browser/.BrowserActivity: 2544 ms (total 2544 ms)
01-24 10:23:53.624: WARN/KeyCharacterMap(355): No keyboard for id 0
01-24 10:23:53.624: WARN/KeyCharacterMap(355): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-24 10:23:54.574: DEBUG/dalvikvm(348): GC_EXPLICIT freed 3965 objects / 267064 bytes in 2364ms
01-24 10:24:01.064: INFO/ActivityManager(61): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=myapp://twitactivity?oauth_token=KjCUNMKg13OClyRjQff94QWKfoRBUpNLE2uF9cJkHA&oauth_verifier=41owXswx5TsxHhRyiviFRkRvcpdekm7akRa2IFFM cmp=nl.gemoro.android.demo/.TwitterScreen }
01-24 10:24:02.174: INFO/global(348): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
01-24 10:24:03.594: INFO/ActivityManager(61): Displayed activity nl.gemoro.android.demo/.TwitterScreen: 2412 ms (total 2412 ms)