2013-03-07 103 views
4

試圖將Twitter與我的應用程序集成。跟着教程,但它不工作。onResume方法不適用於Twitter實施

我有一個PreferenceActivity有一個CheckBoxPreference。如果點擊了,我做到以下幾點:

chkTwitter.setOnPreferenceClickListener(new OnPreferenceClickListener() {   
    @Override 
    public boolean onPreferenceClick(Preference _pref) { 
     Intent fbIntent = new Intent(getApplicationContext(), TwitterConnectActivity.class); 
     _pref.setIntent(fbIntent); 
     return false; 
    } 
}); 

我TwitterConnectActivity被調用時,我配置的Oauth對象那裏調用Twitter的認證網站。

當我點擊授權應用程序,我onResume被調用:

@Override 
    protected void onResume() { 
     super.onResume(); 
     if (this.getIntent()!=null && this.getIntent().getData()!=null){ 
      Uri uri = this.getIntent().getData(); 

      if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { 
       String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER); 

的問題是,this.getIntent().getData()是空的,所以我從來不去的,如果條件內。

我AndroidManifest看起來是這樣的:

<activity 
      android:name=".SettingsActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" > 
      <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:host="my_twitter" android:scheme="callback" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".TwitterConnectActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" > 
     </activity> 

十分肯定我定義我的回調URL,如:private String CALLBACK_URL = "callback://my_twitter";

任何人都可以幫我嗎?

乾杯, 費利佩

+0

+1教給我一個聰明的小動作,使用點擊處理程序動態設置'Preference'的'Intent' :) – Devunwired 2013-03-07 22:27:20

+0

我不知道自己是否對此有信心,因爲我沒有將Twitter添加到在一段時間的應用程序,但它可能是你需要使用onNewIntent? – Catherine 2013-03-07 22:29:50

+0

很高興我幫助@Devunwired :) Catherine的oneNewIntent方法將被調用,具體取決於我如何使用launchMode屬性,我只是使用正常的,所以我不認爲onNewIntent被調用。我會看看! – 2013-03-08 06:30:39

回答

0

使用StartActivityForResult代替。