2012-03-22 42 views
1

我已成功地讓用戶通過OAuth授權我的應用再次高音。回調也起作用,但問題在於此回調返回到恢復活動中的數據爲空。有人知道如何得到它嗎?如何在用戶成功授權我的高音應用程序後從回調中獲取信息?

這是我執行開始認證代碼:

consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
provider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token", 
       "https://api.twitter.com/oauth/access_token", 
       "https://api.twitter.com/oauth/authorize"); 
String authUrl = provider.retrieveRequestToken(consumer,CALLBACK_URL); 
Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show(); 
setConsumerProvider(); 

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl))); 

這是清單我使用:

<uses-sdk android:minSdkVersion="7" /> 
<uses-permission android:name="android.permission.INTERNET"></uses-permission> 

<application 
    ...  

    <activity android:name=".AuthActivity" android:configChanges="orientation" 
     android:label="Comparte en redes sociales" android:launchMode="singleTask"> 
     <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="callback" /> 
     </intent-filter> 
    </activity> 
</application> 

AuthActivity的恢復代碼:

protected void onResume() 
{ 
    super.onResume(); 
    System.out.println("RESUMING!!"); 
    if (this.getIntent()!=null && this.getIntent().getData()!=null) 
    { 

    } 
} 

這裏的this.getIntent().getData()爲空已嘗試其他選項沒有運氣。我需要這些數據來提取uri。任何人都可以幫忙嗎?

回答

1

好吧,發佈問題後,我發現問題。 launchMode="singleTask"正在使活動重新創建,爲了得到uri,我應該將它做到onNewIntent而不是onResume。現在數據已經準備好被讀取:)。抱歉給你帶來不便。

相關問題