I assume that you already have QUICKSTART or DEMO, or something similar up-and-running, so I will refer to these 2 examples. In the BaseDemoActivity.java code, you'll notice that account selection is invoked when connection fails,
@Override public void onConnectionFailed(ConnectionResult result) {
...
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
...
}
... and it comes back in onActivityResult(). I just grab the intent data and get the KEY_ACCOUNT_NAME, it is the selected email. The code below is modified from the DEMO's BaseDemoActivity.java (I mentioned above).
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
if ((resultCode == RESULT_OK) && (data != null) && (data.getExtras() != null ))
// user selected account, get it
String email = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
else
finish(); // user cancelled selection, an easy solution
break;
}
Hope it helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…