Query does not get MMS messages - android

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"));

Related

How to get only sent messages from specific conversation in Android Studio?

ContentResolver cr = getContentResolver();
String[] projection = new String[]{"body", "ct_t", "_id", "address"};
Uri uri = Uri.parse("content://mms-sms/conversations/" + id);
Cursor c = cr.query(uri, projection, null, null, null);
This queries all messages from a specific conversation and I would like only the sent messages to display as I need to distinguish each party of the conversation.
Is there such a thing as a uri like this:
Uri uri2 = Uri.parse("content://mms-sms/conversations/" + id + "/sent/");
You'll need to add a couple of columns to your projection, and include a selection argument in the query() call.
final String[] projection = {"_id", "address", "body", "ct_t", "type", "msg_box"};
final String selection = "(type = 2 OR msg_box = 2)";
final Uri uri = Uri.parse("content://mms-sms/conversations/" + threadId);
Cursor c = getContentResolver().query(uri, projection, selection, null, null);
An SMS message will have a type value of 2 when it has been sent. An MMS message will have the same value, but in the msg_box column.

ContactsContract.Contacts.Entity IllegalArgumentException

I am referring to the https://developer.android.com/reference/android/provider/ContactsContract.Contacts.Entity.html#CONTENT_DIRECTORY. And I want to use the ContactsContract.Contacts.Entity URI for better results. APi level is 11 and my device OS is 4.0. I am using below code. And below is the exception I am getting in logs.
Please advice in which way I can use the ContactsContract.Contacts.Entity API.
Caused by: java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/entities
Cursor phones=null;
ContentResolver cr = getContentResolver();
Uri phoneuri = Contacts.CONTENT_URI;
Uri phone_uri = phoneuri.withAppendedPath(phoneuri, ContactsContract.Contacts.Entity.CONTENT_DIRECTORY);
phones = cr.query(phone_uri, null, null, null, null);
for(int i=0;i<phones.getCount();i++)
{
Log.e("int","f_name="+phones.getColumnName(i));
}
phones.close();
Use this code to get all contacts from android:
ContentResolver cr = getContentResolver();
String[] projection = { ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts._ID };
Cursor contacts = cr.query(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, "UPPER("
+ ContactsContract.Contacts.DISPLAY_NAME + ") ASC");
startManagingCursor(contacts);
Hope this will help you.
int contactId = 111;//one contact's id
Uri contactsUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri entityUri = Uri.withAppendedPath(contactsUri, Contacts.Entity.CONTENT_DIRECTORY);
Cursor c = getContentResolver().query(entityUri,
null,null, null, null);

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 with multiple uri's

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?

How to get track Uri from ContentResolver query?

i am traversing in the phone's memory with the following code.
ContentResolver contentResolver = getContentResolver();
String[] columns = {
MediaColumns._ID,
MediaColumns.TITLE,
AudioColumns.DURATION,
};
final String where = MediaStore.Audio.Media.IS_MUSIC + "=1";
Cursor cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,columns, where, null, null);
while(cursor.moveToNext()) {
String urp = cursor.getString(cursor.getColumnIndex(MediaColumns._ID));
String title = cursor.getString(cursor.getColumnIndex(MediaColumns.TITLE));
Long duration = cursor.getLong(cursor.getColumnIndex(AudioColumns.DURATION));
}
so now my question is, how to get the uri of the cursor items traveresed, like
for first while run i have stored id,title,duration etc metadata and i would also like to
store that tracks URI, also i would like to convert that URI from content// scheme to file scheme.
Any help will be greatful
thankyou
String.valueOf(cur.getColumnIndex(android.provider.MediaStore.MediaColumns.DATA)));
http://android-er.blogspot.fr/2011/04/convert-uri-to-real-path-format.html

Categories

Resources