I've got a working twitter4j implementation but the OAuth process for authorizing the app leaves the Android web browser running behind the application. I'd like to try implementing my own webview in a launched activity so I can finish() it or at least clean up after my app. Problem is, now I have to figure out how to return the authURL to my main activity.
What's the best way to return the authURL? I've subclassed a webview widget and am experimenting with a way to return the authURL in onPageFinished() but not quite there yet.
private class myWebViewClient extends WebViewClient
{
@Override
public void onPageFinished (WebView view, String url)
{
Log.d (TAG, "onPageFinished");
super.onPageFinished (view, url);
if (url.contains (TwitterLibActivity.CALLBACK_URL) == true)
{
/*
mRetIntent = new Intent();
mRetIntent.putExtra ("verifed", url);
setResult (RESULT_OK, mRetIntent);
*/
Log.d (TAG, "have auth url:" + url);
finish();
}
}
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url)
{
Log.d (TAG, "myWebViewClient url:" + url);
//return super.shouldOverrideUrlLoading (view, url);
return (false);
}
}
I recently found this article working only with twitter4j without singpost, this work with webview and can help you: http://davidcrowley.me/?p=410
Greetings
TwitterOAuthView is a WebView subclass dedicated to Twitter OAuth on Android, using twitter4j.
Twitter OAuth View for Android using twitter4j
http://darutk-oboegaki.blogspot.jp/2012/07/twitter-oauth-view-for-android-using.html
Since it is implemented as a subclass of View, it can be integrated into the Android layout system seamlessly. This fact makes TwitterOAuthView an easily-reusable UI component.
Its usage is very simple. Just call start() method
// Start Twitter OAuth process. Getting a request token, opening Twitter's
// authorization page, and getting an access token are performed.
view.start(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL, true, listener);
and receive its result via TwitterOAuthView.Listener interface.
// Definition of TwitterOAuthView.Listener interface.
void onSuccess(TwitterOAuthView view, AccessToken accessToken);
void onFailure(TwitterOAuthView view, TwitterOAuthView.Result result);
An example of Activity implementation using TwitterOAuthView can be found at GitHub TwitterOAuthView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With