Query with multiple uri's - android

Uri contactUri1 = Uri.withAppendedPath(
ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number1));
Cursor phones = getContentResolver()
.query(contactUri1, PEOPLE_PROJECTION, null, null, null);
This works. I can get what I need in the cursor given number1.
What I want is to query for multiple numbers and get all the results in the same cursor.
EXAMPLE:
Uri contactUri1 = ...
Uri contactUri2 = ...
Cursor phones = getContentResolver().query(... //Both URI's
Is that possible?

Related

Content Resolver query PHOTO_URI from multiple numbers

I want to make a single query that will return the ContactsContract.PhoneLookup.PHOTO_URI for multiple numbers
Now i use this:
Cursor contactLookupCursor = context.getContentResolver().query(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, UriContactNumber),
new String[]{ContactsContract.PhoneLookup.PHOTO_URI}, null, null, null);
while (contactLookupCursor.moveToNext()) {
photoUri = contactLookupCursor.getString(contactLookupCursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup.PHOTO_URI));
}
I want to pas more numbers to Uri.withAppendedPath. Can i do that?

Empty cursor row when filtering with selection

I'm not confident with cursors and I'm facing some problem when filtering one with a WHERE clause.
What I'm doing:
ContentResolver contentResolver = context.getContentResolver();
Uri uriConversation = Uri.parse("content://mms-sms/conversations/");
String[] projection = new String[]{"*"};
String selection = "address=" + phoneNumberForThread;
Cursor cursor = contentResolver.query(uriConversation, projection, null, null, null);
Executing this code the cursor get filled and works perfectly.
However, if I swap the null selection argument with my selection String as
Cursor cursor = contentResolver.query(uriConversation, projection, selection, null, null);
I then get an empty cursor. I even check for !phoneNumberForThread.isEmpty()
I think I'm doing something wrong but again I am not confident with cursor yet.
Any help would be really appreciated.
If your input variabel is stored as a string data type, you should enclose it with ' as such:
String selection = "address='" + phoneNumberForThread + "'";

How to add where clause while querying for mms-sms conversation?

I need a conversation cursor which does not have given addresses.
This is how i am getting the cursor :
final Uri inboxURI = Uri.parse("content://mms-sms/conversations/");
final String[] projection = new String[] { Sms._ID, Sms.THREAD_ID, Sms.ADDRESS, Sms.BODY, Sms.DATE, Sms.READ};
Cursor cursor = cr.query(inboxURI, projection, Sms.ADDRESS+" NOT IN (?)", new String[]{"456454"}, Telephony.Sms.Inbox.DEFAULT_SORT_ORDER);
This gives me an empty cursor. However this works fine if null is given as selection and selection_args.
Is this correct way?
Thanks in advance.

Querying the MMS-SMS conversation

I am implementing the methods discussed here How to Read MMS Data in Android
Here is the snippet.
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor query = contentResolver.query(uri, projection, null, null, null);
When I try to get the data through the cursor, I do not get the IDs of the MMS messages. I only get the IDs of the SMS messages. I have two MMS in my inbox and their address "number" do not show up.

Query does not get MMS messages

I am implementing the method discussed here How to Read MMS Data in Android. Here is the code snippet:
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor query = contentResolver.query(uri, projection, null, null, null);
When I try to get the data through the cursor, I do not get the IDs of the MMS messages. I only get the IDs of the SMS messages.
change your code as:
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Uri MMSSMS_FULL_CONVERSATION_URI = Uri.parse("content://mms-sms/conversations");
Uri uri = MMSSMS_FULL_CONVERSATION_URI.buildUpon().
appendQueryParameter("simple", "true").build();
Cursor query = contentResolver.query(uri, projection, null, null, null);
My code is right. It just needs this code to get the id of the messages
cursor.moveToFirst();
String address = cursor.getString(cursor.getColumnIndex("_id"));

Categories

Resources