I Want To Fetch And View Sms Conversations?
ContentResolver cr = getContentResolver(); Cursor cur = cr.query(Uri.parse('content://sms/conversations/'), null,null,null, null); is not working why?
Solution 1:
You can fetch sms-inbox:
UrimSmsinboxQueryUri= Uri.parse("content://sms/inbox");
Cursorcursor1= getContentResolver().query(mSmsinboxQueryUri,newString[] { "_id", "thread_id", "address", "person", "date","body", "type" }, null, null, null);
startManagingCursor(cursor1);
String[] columns = newString[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
Stringcount= Integer.toString(cursor1.getCount());
while (cursor1.moveToNext()){
Stringaddress= cursor1.getString(cursor1.getColumnIndex(columns[0]));
Stringname= cursor1.getString(cursor1.getColumnIndex(columns[1]));
Stringdate= cursor1.getString(cursor1.getColumnIndex(columns[2]));
Stringmsg= cursor1.getString(cursor1.getColumnIndex(columns[3]));
Stringtype= cursor1.getString(cursor1.getColumnIndex(columns[4]));
}
}
You can fetch other sent items by changing the URI.
UrimSmsinboxQueryUri= Uri.parse("content://sms/sent");
You can do that with MMS also with URI:
RECEIVED_MMS_CONTENT_URI = "content://mms/inbox";SENT_MMS_CONTENT_URI = "content://mms/sent";
For SMS-MMS both:
Uriuri= Uri.parse("content://mms-sms/conversations/");
Solution 2:
finally got what i needed!
ContentResolvercontentResolver= getContentResolver();
final String[] projection = newString[]{"*"};
Uriuri= Uri.parse("content://mms-sms/conversations/");
Cursorquery= contentResolver.query(uri, projection, null, null, null);
Solution 3:
I am not sure and i haven't tried yet, but i think this may be of your work.
UriuriSms= Uri.parse("content://sms/inbox");
Cursorc= getContentResolver().query(uriSms, null,null,null,null);
I had found this earlier from this answer: How to delete an SMS from the inbox in Android programmatically?
Solution 4:
String[] projection = {"thread_id", "MAX(date)", "COUNT(*) AS msg_count", "body"};
Cursorcursor= getContentResolver().query(Telephony.Sms.CONTENT_URI, projection, "thread_id) GROUP BY (thread_id", null, null);
Solution 5:
This function is for fetching conversations
privatevoidgetSMSCOnversationlist() {
UriSMS_INBOX = Uri.parse("content://sms/conversations/");
Cursor c = getActivity().getContentResolver().query(SMS_INBOX, null,null, null, "date desc");
String[] count = newString[c.getCount()];
String[] snippet = newString[c.getCount()];
String[] thread_id = newString[c.getCount()];
c.moveToFirst();
for (int i = 0; i < c.getCount(); i++) {
count[i] = c.getString(c.getColumnIndexOrThrow("msg_count")).toString();
thread_id[i] = c.getString(c.getColumnIndexOrThrow("thread_id")).toString();
snippet[i] = c.getString(c.getColumnIndexOrThrow("snippet")).toString();
Toast.makeText(getActivity(), count[i] + " - " + thread_id[i] + " - " + snippet[i]+ " - " , Toast.LENGTH_LONG).show();
c.moveToNext();
}
c.close();
}
Post a Comment for "I Want To Fetch And View Sms Conversations?"