I have another solution to get a phone number when telephony manager returns blank. I hope it'll help you.
Here is my sample code:
public static final String main_data[] = {
"data1", "is_primary", "data3", "data2", "data1", "is_primary", "photo_uri", "mimetype"
};
object object = (TelephonyManager) context.getSystemService("phone");
if (!TextUtils.isEmpty(((TelephonyManager) (object)).getLine1Number())) {
}
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;
}
if (s.equals("vnd.android.cursor.item/phone_v2")) {
String s1 = ((Cursor) (object)).getString(4);
boolean flag1;
if (((Cursor) (object)).getInt(5) > 0) {
flag1 = true;
} else {
flag1 = false;
}
Toast.makeText(SampleActivity.this, "Phone:-" + s1, Toast.LENGTH_LONG).show();
}
} while (true);
((Cursor) (object)).close();
}
Also don't forget to add these two permissions: