2013-12-19 33 views
1

onCreate方法LoginActivity的,的Android AccountPicker - 無活動來處理意圖

button.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

     Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"}, 
       false, null, null, null, null); 
     startActivityForResult(intent, SOME_REQUEST_CODE); 
    } 
}); 

我也有FF方法:

protected void onActivityResult(final int requestCode, final int resultCode, 
     final Intent data) { 
    if (requestCode == SOME_REQUEST_CODE && resultCode == RESULT_OK) { 
     ... 
    } 
} 

AndroidManifest

<activity 
    android:name="LoginActivity" 
    android:label="@string/title_activity_login" > 
</activity> 

當在運行2.3.6的Android設備上測試應用程序,我遇到了下面的錯誤:

ActivityNotFound No Activity found to handle intent com.google.android.gms.common.account.CHOOSE_ACCOUNT 

如何解決?

回答

0

設備是否安裝了Google Play服務?還請查看您在代碼中使用的Google Play服務庫的版本。您需要使用Froyo版本。

您可以檢查可用性如下:

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); 
       if (status != ConnectionResult.SUCCESS) 
       { 
         Log.e(App.TAG, String.valueOf(status)); 
         Toast.makeText(this, getString(R.string.gps_missing), Toast.LENGTH_LONG).show(); 
         finish(); 
         return; 
       } 

http://android-developers.blogspot.in/2013/10/google-play-services-40.html

更新: 也重溫你如何獲得的意圖。這是我怎麼在我的應用程序:

try 
         { 

           startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER); 
         } 
         catch (ActivityNotFoundException e) 
         { 

           Toast.makeText(this, getString(R.string.gps_missing), Toast.LENGTH_LONG).show(); 

           return; 
         } 

完整的源: https://github.com/madhur/GAnalytics/blob/develop/src/in/co/madhur/ganalyticsdashclock/MainActivity.java

+0

如果您不使用獲取意圖的新方法會發生什麼? – Ken

1

由於您使用的是谷歌播放服務組件(在AccountPicker),你需要確保谷歌Play服務存在且在調用使用該服務的方法之前在用戶設備上保持最新狀態,如setup guide中所述。

相關問題