Ich habe versucht, Kontaktname (zB "Jose") & Kontakt Telefonnummer Typ Wert (zB "Home", "Arbeit", etc.) vom Telefon Kontakt für bestimmte Telefonnummer (z. B. "9600515852")So erhalten Sie Telefonnummern-Typenschild von gegebener Telefonnummer in Android
für diesen habe ich bellow-Code verwendet. aber ich kann Kontaktname nur erhalten. Ich bekomme App-Absturz, wenn ich versuche, den Telefonnummern-Typ zu bekommen.
Bitte führen Sie mich.
String number = getContactName(this, "9600515852");
Toast.makeText(getApplicationContext(),number,Toast.LENGTH_LONG).show();
private String getContactName(Context context, String number) {
String TAG ="" ;
String name = null, label=null;
int type=0;
// define the columns I want the query to return
String[] projection = new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME,ContactsContract.PhoneLookup._ID };
// encode the phone number and build the filter URI
Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
// query time
Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null);
if(cursor != null) {
if (cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
// type = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
} else {
Log.v(TAG, "Contact Not Found @ " + number);
}
cursor.close();
}
return name+" - "+number;
}