What does Uri from Contact Manager point to?

I am trying to select a phone number from my contact list. Everything works fine, but I keep the phone number. I would like to keep a pointer to a phone number so that if it has changed, I get a new number.

I think I just need to save the Uri that I will return to onActivityResult, but I'm not sure what exactly this indicates.

doc says startActivityForResult () * "returns the URI of the contents of the selected row. The URI form is the URI of the contents of the table with the string LOOKUP_ID added to it." *

Can someone point me to a document or explain what Uri is? Is the best way to save a pointer to a phone number besides saving this uri and re-querying?

By the way, I can just save both and implement a listener in the contacts database and only re-query if the database is updated.

I select a contact using the contact picker as such;

Intent pickContactIntent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST); 

Then, selecting it, I get a phone number using something like this:

 public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PICK_CONTACT_REQUEST) { if (resultCode == android.app.Activity.RESULT_OK) { Uri contactUri = data.getData(); Cursor cursor = contentResolver.query(contactUri,null, null, null, null); if (cursor != null && cursor.moveToFirst()) { int columnPhone = cursor.getColumnIndex(Phone.NUMBER); String number = cursor.getString(columnPhone); } } } } 
+4
source share

Source: https://habr.com/ru/post/1500579/


All Articles