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?
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With