Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to get "Owner" contact info in Android?

I haven't been able to find a straight answer on this. Can anyone tell me if it's possible to get the contact info of the phone's owner in an Android App?

like image 324
wajiw Avatar asked Jun 03 '11 02:06

wajiw


2 Answers

I have found a very easy way (got it from digging into the 4.1 Messaging app!)

projection for cursor is

final String[] SELF_PROJECTION = new String[] { Phone._ID,Phone.DISPLAY_NAME, };

Cursor is :

Cursor cursor = activity.getContentResolver().query(Profile.CONTENT_URI, SELF_PROJECTION, null, null, null);

now just do a simple

cursor.moveToFirst():

and then fetch the contact id via

cursor.getString(0)

and the contact name via

cursor.getString(1)

and..... you're done!

like image 134
Daksh Avatar answered Sep 17 '22 11:09

Daksh


So the answer is technically no. The only way I've found so far to get owner's data is through the account manager. Here's an example of how to use it:

final AccountManager manager = AccountManager.get(this);
final Account[] accounts = manager.getAccountsByType("com.google");
final int size = accounts.length;
String[] names = new String[size];
for (int i = 0; i < size; i++) {
  names[i] = accounts[i].name;
}

For more info see: http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager

like image 33
wajiw Avatar answered Sep 17 '22 11:09

wajiw