mardi 30 septembre 2014

How do I get the phone owner's full name through AccountPicker?


Vote count:

0




I need both the phone owner's name and email.


I successfully obtained the name through using ContactsContract.Profile (how to get firstname and lastname of Android phone owner?), but I wasn't able to obtain an email. It is possible to get the email, but it isn't 100% that you'll get any data whatsoever (so even getting the name isn't 100%).


Hence, I'm using AccountPicker, AccountManager & the Google Play Services API to try to get it. That being said, I understand that this method doesn't guarantee getting the email or name either, but I'd at least like to know how to get the name. The following is how I got the email:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_register);
int REQUEST_EMAIL_CODE = 1;

try {
Intent intent = AccountPicker.newChooesAccountIntent(null, null,
new String[] { "com.google" }, false, null, null, null, null);
startActivityForResult(intent, REQUEST_EMAIL_CODE);
} catch (ActivityNotFoundException e) {
//handle error here
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == RESULT_OK) {
String userEmailAddress = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
}
}


I'm not sure how I would obtain the name. I've tried replacing AccountManager.KEY_ACCOUNT_NAME with different things, but nothing yielded the result and usually I got an error. Maybe now that I have the email, there is a way to get the name from using it some key?



asked 36 secs ago

David

786






How do I get the phone owner's full name through AccountPicker?

Aucun commentaire:

Enregistrer un commentaire