I am working in app. I need to get phone number programmatically. I follow this link
but i get phone number in one device, many times i am not getting .Have any perfect solution .
I am working in app. I need to get phone number programmatically. I follow this link
but i get phone number in one device, many times i am not getting .Have any perfect solution .
you can try this but not sure for all the device. It works only on some devices.
public static String getPhoneNumber(Context context) {
String s1="";
String main_data[] = {"data1", "is_primary", "data3", "data2", "data1",
"is_primary", "photo_uri", "mimetype"};
Object object = context.getContentResolver().
query(Uri.withAppendedPath(android.provider.ContactsContract.Profile.CONTENT_URI, "data"),
main_data, "mimetype=?",
new String[]{"vnd.android.cursor.item/phone_v2"},
"is_primary DESC");
if (object != null) {
do {
if (!((Cursor) (object)).moveToNext())
break;
// This is the phoneNumber
s1 =((Cursor) (object)).getString(4);
} while (true);
((Cursor) (object)).close();
}
return s1;
}