How to Differentiate MMS and SMS in android? - android

How to Differentiate MMS and SMS via MMS/SMS listeners in Android? Because I got SMS counts as in MMS counts?
I am calculating Total MMS as using following code.
Uri mmsInboxUri = Uri.parse("content://mms/inbox");
Uri mmsSentUri = Uri.parse("content://mms/sent");
Cursor mmsInboxCursor = getContentResolver().
query(mmsInboxUri ,new String[] {"_id"}, null, null);
Cursor mmsSentCursor = getContentResolver().
query(mmsSentUri ,new String[] {"_id"}, null, null);
int mmsCount = mmsInboxCursor.getCount() + mmsSentCursor.getCount();

You should check the column ct_t. If it's a MMS it should be equal to application/vnd.vap_multipart.related.

Related

Reading last sms from a particular sender

Im building a app that is reading last sms from spec number (vb# 8888). Code is working great. I only have one prob. When i get a new sms from other number (vb# 7777)my code stops reading sms from (v#8888). if i delete the new sms from (7777) than my code strats working again. I'm using this to update a string in my app. Can someone help me
This is my code
Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri, null, null, null, null);
String[] columns = new String[]{"address", "body"};
if(cursor1.moveToFirst()) {
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
if address.equalsIgnoreCase("+597*******")) {
body = cursor1.getString(cursor1.getColumnIndex(columns[3]));
Koers = (TextView) findViewById(R.id.Koersdiedag);
Koers.setText(body);//body
Your code is just reading the most recent message in the inbox, whomever it's from. If you want the most recent message from that particular number, you can adjust your query to match the number, and limit the results to one record.
Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
String[] projection = {"address", "body"};
String phoneNumber = "+597*******";
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
projection,
"address = ?",
new String[] {phoneNumber},
"date DESC LIMIT 1");
if (cursor1 != null && cursor1.moveToFirst()) {
body = cursor1.getString(cursor1.getColumnIndex("body"));
Koers = (TextView) findViewById(R.id.Koersdiedag);
Koers.setText(body);
}

Determine if a phone number has sms messages in android

Is there a way to tell if a phone number has an sms(s) in android ??
I want to know if there is a way to tell using the sms content porvider I know its not documented and not recommanded to use but is there a way to tell ??
what i have tried .
this statement will get all the inbox sms(s)
cursor = getContentResolver().query(
Uri.parse("content://sms/inbox"), null, null, null,
null);
I cant use the where clause like this
cursor = getContentResolver().query(
Uri.parse("content://sms/inbox"), "address =?", new String[]{"001435436654747"}, null,
null);
because the number may be stored without the global code the "001" or such .
is there a work around for this ??
Hi you can use below code to do this , I use this in my application to listen incoming sms to reply automaticaly.
Uri myMessage = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(myMessage, new String[] {
"_id", "address", "date", "body",
"read" }, null, null, null);
System.out.println(Number);
while (c.moveToNext()) {
Number = c.getString(c.getColumnIndexOrThrow("address")).toString();
if (Number.equals("001435436654747")) {
// DO YOUR STUFF
}
}

Android SMS count database

I am looking for code to get the total sent-sms count in android mobiles. If I use content://sms/sent/ for querying the database I get the sms count of the available sent sms in the mobile, but I want the total sms that is sent from buying the mobile.
Retrieve All SMS messages in the Android
The URI (content://sms/) will used to retrive the all SMS messages, also we can split up by the message type as well as.
Uri allMessage = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(allMessage, null, null, null, null);
while (c.moveToNext()) {
String row = c.getString(1);
}
you can get the all inbox/outbox here
change your URI
use this one: content://sms/

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.

Set sms as read in Android

In my application I need to read sms coming from only a number, and when i receive it I need to set it as read automatically, without setting it in the sms android application, but from my app. How can I do?
Thanks!
Let me update this:
ContentValues values = new ContentValues();
values.put("read",true);
getContentResolver().update(Uri.parse("content://sms/"),values, "_id="+SmsMessageId, null);
SmsMessageId is _id of message, which you find in SMS database.
A short example:
Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext()) {
// Retrieve sms
// see column "address" for comparing
// Then update the sms and set the column "read" to 1
}

Categories

Resources