Name obtained by phone number
Hot1 Read twice 21 hours ago Tags: Phone number before 2.0: Public String getname (context CTX, string number ){ String [] projection = new string [] { Contacts. Phones. display_name, Contacts. Phones. Number }; // Encode the phone number and build the filter URI Uri contacturi = URI. withappendedpath (contacts. Phones. content_filter_url, Uri. encode (number )); // Query time Cursor c = CTX. getcontentresolver (). Query (contacturi, projection, null, Null, null ); // If the query returns 1 or more results // Return the first result If (C. movetofirst ()){ String name = C. getstring (C. getcolumnindex (contacts. Phones. display_name )); Log. D ("debug", "XYZ _" + name + "is calling "); Return name; } Return ""; }
2.0 and later: Public String getname (context CTX, string number ){ Uri uri = URI. withappendedpath (contactscontract. phonelookup. content_filter_uri, Uri. encode (number ));
// Query the filter URI String [] projection1 = new string [] {phonelookup. display_name }; Cursor cursor1 = CTX. getcontentresolver (). Query (Uri, projection1, null ); If (cursor1.movetofirst ()){ String name = cursor1.getstring (cursor1 . Getcolumnindex (phonelookup. display_name )); Int phonenameindex = cursor1.getcolumnindex (phonelookup. display_name ); String phonenamestr = cursor1.getstring (phonenameindex ); Log. D ("debug", "XYZ _" + phonenamestr + "is calling "); Return name; } Return "";}