According to the 4.4 SMS APIs, the new version provides functionality to:
allow apps to read and write SMS and MMS messages on the device
I can't find any information on this functionality, nor any samples in the new SDK. This is what I have so far for reading new incoming messages.
However, I would like to read existing messages stored on the deivce:
// Can I only listen for incoming SMS, or can I read existing stored SMS?
SmsMessage[] smsList = Telephony.Sms.Intents.getMessagesFromIntent(intent);
for(SmsMessage sms : smsList) {
Log.d("Test", sms.getMessageBody())
}
Please note: I know about using the SMS Content Provider, however this method is unsupported. According to the linked APIs, I should be able to do this in a supported way.
It looks like you would be able to use this class to get it working. The package is Telephony.Sms.Conversations.
Although the following code uses the content provider method, this is now an official API added in API Level 19 (KitKat) for reading the SMS messages.
public List<String> getAllSmsFromProvider() {
List<String> lstSms = new ArrayList<String>();
ContentResolver cr = mActivity.getContentResolver();
Cursor c = cr.query(Telephony.Sms.Inbox.CONTENT_URI, // Official CONTENT_URI from docs
new String[] { Telephony.Sms.Inbox.BODY }, // Select body text
null,
null,
Telephony.Sms.Inbox.DEFAULT_SORT_ORDER); // Default sort order
int totalSMS = c.getCount();
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
lstSms.add(c.getString(0));
c.moveToNext();
}
} else {
throw new RuntimeException("You have no SMS in Inbox");
}
c.close();
return lstSms;
}
I did it like the following. Create SMSObject:
public class SMSObject {
private String _id;
private String _address;
private String _msg;
private String _readState; // "0" for have not read sms and "1" for have
// read sms
private String _time;
private String _folderName;
//+ getter and setter methods and
#Override
public String toString() {
return "SMSObject [_id=" + _id + ", _address=" + _address + ", _msg="
+ _msg + ", _readState=" + _readState + ", _time=" + _time
+ ", _folderName=" + _folderName + "]";
}
And here a simple function, which simply logs all current SMS-Objects
private void readSMS() {
List<SMSObject> lstSms = new ArrayList<SMSObject>();
SMSObject objSms = new SMSObject();
Uri message = Uri.parse("content://sms/");
ContentResolver cr = this.getContentResolver();
Cursor c = cr.query(message, null, null, null, null);
// this.startManagingCursor(c);
int totalSMS = c.getCount();
Log.d("SMS Count->", "" + totalSMS);
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
objSms = new SMSObject();
objSms.setId(c.getString(c.getColumnIndexOrThrow("_id")));
objSms.setAddress(c.getString(c
.getColumnIndexOrThrow("address")));
objSms.setMsg(c.getString(c.getColumnIndexOrThrow("body")));
objSms.setReadState(c.getString(c.getColumnIndex("read")));
objSms.setTime(c.getString(c.getColumnIndexOrThrow("date")));
if (c.getString(c.getColumnIndexOrThrow("type")).contains("1")) {
objSms.setFolderName("inbox");
} else {
objSms.setFolderName("sent");
}
lstSms.add(objSms);
Log.d("SMS at " + i, objSms.toString());
c.moveToNext();
}
}
// else {
// throw new RuntimeException("You have no SMS");
// }
c.close();
// return lstSms;
}
I found this some days ago, can't remember from what site;
You can only restore messages if the user has chosen to make the app the default sms app. This may or may not answer your question fully. I haven't tried this yet
Query the current default SMS app's package name and save it.
String defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(context);
Request the user change the default SMS app to your app in order to restore SMS messages (you must be the default SMS app in order to write to the SMS Provider).
Intent intent = new Intent(context, Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Sms.Intents.EXTRA_PACKAGE_NAME, context.getPackageName());
startActivity(intent);
Related
Working on an Android app that retreives SMS messages on the device using this code;
public void refreshSmsSent() {
ContentResolver contentResolver = getContentResolver();
arrayAdapter.clear();
Cursor c = contentResolver.query(Telephony.Sms.Sent.CONTENT_URI, // Official CONTENT_URI from docs
new String[] { Telephony.Sms.Sent.ADDRESS, Telephony.Sms.Sent.BODY, Telephony.Sms.Sent._ID, Telephony.Sms.Sent.ERROR_CODE, Telephony.Sms.Sent.TYPE }, // Select body text
null,
null,
Telephony.Sms.Sent.DEFAULT_SORT_ORDER); // Default sort order
int totalSMS = c.getCount();
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
String str = "To: " + c.getString(0) +
"\n" + c.getString(1) + "\n" + c.getString(2) + "\n" + c.getString(3) + "\n" + c.getString(4) + "\n";
arrayAdapter.add(str);
c.moveToNext();
}
} else {
Toast.makeText(this, "Nothing here..!", Toast.LENGTH_SHORT).show();
}
c.close();
}
This works absolutely fine for Telephony.Sms.Sent and Telephony.Sms.Inbox but I can't seem to get anything back using the same code with Telephony.Sms.Outbox or Telephony.Sms.Draft
I think I have the required permissions in place in the manifest;
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
Question:
Ideally, I'd like to get all SMS records on the device and process (e.g. delete, resend) each one in my own code... is there a method I can use to retrieve all SMS messages on the device in one go using a single query..?
A day later... some progress... this code using Telephony.Sms gets all Sent and Inbox entries in single query...
public void refreshSmsAll() {
ContentResolver contentResolver = getContentResolver();
arrayAdapter.clear();
Cursor c = contentResolver.query(Telephony.Sms.CONTENT_URI, // Official CONTENT_URI from docs
new String[] { Telephony.Sms.ADDRESS, Telephony.Sms.BODY, Telephony.Sms.TYPE, Telephony.Sms.ERROR_CODE, Telephony.Sms._ID }, // Select body text
null,
null,
Telephony.Sms.Draft.DEFAULT_SORT_ORDER); // Default sort order
int totalSMS = c.getCount();
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
String str = "X: " + c.getString(0) +
"\n" + c.getString(1) + "\n" + c.getString(2) + "\n" + c.getString(3) + "\n" + c.getString(4) + "\n";
arrayAdapter.add(str);
c.moveToNext();
}
} else {
Toast.makeText(this, "Nothing here..!", Toast.LENGTH_SHORT).show();
}
c.close();
}
However, what it doesn't get is Outbox and Draft... any ideas, anyone..?
Another 2hrs later... getting somewhere with the delete now...
public void onDeleteMsg(View view) {
ContentResolver contentResolver = getContentResolver();
boolean isSmsDeleted = false;
try {
contentResolver.delete(Telephony.Sms.CONTENT_URI, "_id=?",new String[] { "371" });
isSmsDeleted = true;
Toast.makeText(this, "Deleted..!", Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
isSmsDeleted = false;
Toast.makeText(this, "NOT Deleted..!", Toast.LENGTH_SHORT).show();
}
}
Only works if my sms app is the default, which is fine, so that means I have to insert and delete messages in the sms database myself..!
public void onInsertMsg(View view) {
ContentResolver contentResolver = getContentResolver();
ContentValues values = new ContentValues();
values.put(Telephony.Sms.ADDRESS, "123456789");
values.put(Telephony.Sms.BODY, "The message");
values.put(Telephony.Sms.TYPE, "2");
boolean isSmsDeleted = false;
try {
contentResolver.insert(Telephony.Sms.CONTENT_URI,values);
Toast.makeText(this, "Inserted..!", Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
Toast.makeText(this, "NOT Inserted..!", Toast.LENGTH_SHORT).show();
}
}
Scenario:
Along with plenty of received/sent sms, I've created a draft message and forced a failed message to a dud number, neither of which appear in any query.
Interestingly, if I force a manual re-send on the failed message it appears in the Sent query for the duration of the re-try, then it isn't present.
I'm assuming that anything I can see in the standard messaging app for the device should be available to my "home-made" app, understanding that there may be some limitations depending on which one is the default SMS app.
you are using the wrong classes to fetch sms.
If you have to use these classes to fetch relevant information :
Telephony.Sms.Inbox.CONTENT_URI - For Inbox message
Telephony.Sms.Sent.CONTENT_URI - For sent messages .
Reference : https://developer.android.com/reference/android/provider/Telephony.Sms.
My Github code for fetching Inbox SMSs :
https://github.com/meajay/SampleSmsApp/blob/master/app/src/main/java/assignment/com/smsapplication/utils/SmsAPI.java
Background
Contacts on the address book can have an account data that's attached to them.
Each app can have an account, and then add its own information for the contact.
Apps such as Telegram, WhatsApp, Viber,... - all create an account that adds information and/or actions to contacts.
Here's an example of a contact that has both WhatsApp and Viber accounts for it:
The problem
I'm trying to figure out how to fetch all contacts that have a specified account.
Since WhatsApp is the most popular that I know of, my tests focus on it.
My problem is that some users claim what I did barely returns contacts, and some claim it doesn't show even a single one. It seems to usually work, and in my case it always worked, but something is probably not good on the code.
What I've tried
I got to make the next code, which to me seems to work, getting a map of phone-to-contact-info, of all WhatsApp contacts.
The idea is to get all possible information of WhatsApp contacts, vs all basic contacts data, and merge those that match the same lookup-key.
I tried to use a better query of joining, but I failed. Maybe it is possible too, and might be more efficient.
Here's the code:
/**
* returns a map of lookup-key to contact-info, of all WhatsApp contacts
*/
#NonNull
public HashMap<String, ContactInfo> getAllWhatsAppPhones(Context context) {
ContentResolver cr = context.getContentResolver();
final HashMap<String, ContactInfo> phoneToContactInfoMap = new HashMap<>();
final HashMap<String, String> whatsAppLookupKeyToPhoneMap = new HashMap<>();
final String phoneMimeType = Phone.CONTENT_ITEM_TYPE;
final Cursor whatsAppCursor;
whatsAppCursor = cr.query(Data.CONTENT_URI,
new String[]{Phone.NUMBER, Phone.LOOKUP_KEY},
Phone.MIMETYPE + " = ?", new String[]{WhatsAppStuff.WHATS_APP_MIME_TYPE}, null);
if (whatsAppCursor == null)
return phoneToContactInfoMap;
Cursor contactCursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
//null,
new String[]{
Contacts.LOOKUP_KEY, Contacts._ID, Contacts.PHOTO_THUMBNAIL_URI,
ContactsContract.Contacts.DISPLAY_NAME, // ContactsContract.CommonDataKinds.Phone.NUMBER,
},
"(" + Phone.MIMETYPE + " IS NULL OR " + Phone.MIMETYPE + " = '" + phoneMimeType + "') AND ("
+ ContactsContract.RawContacts.ACCOUNT_TYPE + " = 'com.google' OR " + ContactsContract.RawContacts.ACCOUNT_TYPE + " IS NULL)",
null, null);
if (contactCursor == null) {
whatsAppCursor.close();
return phoneToContactInfoMap;
}
int progress = 0;
final int phoneNumberIdx = whatsAppCursor.getColumnIndex(Phone.NUMBER);
final int lookupKeyIdx = whatsAppCursor.getColumnIndex(Phone.LOOKUP_KEY);
while (whatsAppCursor.moveToNext()) {
final String phoneNumberValue = whatsAppCursor.getString(phoneNumberIdx);
final int endIndex = phoneNumberValue.indexOf("#");
if (endIndex < 0)
continue;
String lookupKey = whatsAppCursor.getString(lookupKeyIdx);
final String phone = phoneNumberValue.substring(0, endIndex);
if (!phone.isEmpty() && StringUtil.isAllDigits(phone)) {
//Log.d("AppLog", "whatsApp phone:" + phone + " " + lookupKey);
whatsAppLookupKeyToPhoneMap.put(lookupKey, phone);
}
if (markedToCancel != null && markedToCancel.get()) {
whatsAppCursor.close();
contactCursor.close();
return phoneToContactInfoMap;
}
if (progressListener != null)
progressListener.onProgressUpdate(progress++, maxProgress);
}
whatsAppCursor.close();
if (whatsAppLookupKeyToPhoneMap.isEmpty())
return phoneToContactInfoMap;
//Log.d("AppLog", "getting info about whatsapp contacts");
final int idColIdx = contactCursor.getColumnIndex(Contacts._ID);
final int displayNameColIdx = contactCursor.getColumnIndex(Contacts.DISPLAY_NAME);
final int lookupKeyColIdx = contactCursor.getColumnIndex(Contacts.LOOKUP_KEY);
final int photoColIdx = contactCursor.getColumnIndex(Contacts.PHOTO_THUMBNAIL_URI);
while (contactCursor.moveToNext()) {
String lookupKey = contactCursor.getString(lookupKeyColIdx);
String phoneNumber = whatsAppLookupKeyToPhoneMap.get(lookupKey);
if (phoneNumber == null)
continue;
ContactInfo contactInfo = new ContactInfo();
contactInfo.lookupKey = lookupKey;
contactInfo.displayName = contactCursor.getString(displayNameColIdx);
contactInfo.photoThumbUriStr = contactCursor.getString(photoColIdx);
contactInfo.whatsAppPhoneNumber = phoneNumber;
contactInfo.contactId = contactCursor.getLong(idColIdx);
phoneToContactInfoMap.put(phoneNumber, contactInfo);
if (markedToCancel != null && markedToCancel.get()) {
contactCursor.close();
return phoneToContactInfoMap;
}
if (progressListener != null)
progressListener.onProgressUpdate(progress++, maxProgress);
}
contactCursor.close();
return phoneToContactInfoMap;
}
The question
As I wrote, the above code only usually works.
How come it only usually works? What's missing to fix it?
Should I use Contacts.getLookupUri instead of lookup key? If so, how should I change the code above to use it instead?
I tried to use a URI instead of a lookup-key, but then it didn't find any of them inside the normal contacts.
The main issue I see that can explain why users won't see results from your code, is that you're assuming all the contacts are stored on a Google account.
While this is the default behavior in some devices, it's not the default on all devices, also, users can freely change their contacts storage to any other location (yahoo contacts, MS exchange, phone-only (unsynced), etc.)
Having that said, if your only requirement is to
fetch all contacts that have a specified account.
I think that's a much better alternative then your 2 queries (one of which runs over all contacts, not just the required ones):
// Uri to query contacts that have a RawContact in the desired account
final Uri.Builder builder = Contacts.CONTENT_URI.buildUpon();
builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, whatsappAccountName);
builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, whatsappAccountType);
Uri uri = builder.build();
String[] projection = new String[]{ Contacts.LOOKUP_KEY, Contacts._ID Contacts.DISPLAY_NAME }; // add more if needed
// boo-yaa!
Cursor cur = cr.query(uri, projection, null, null, null);
I want to delete messages of particular contact number programmatically in Android Lollipop and Marshmallow.
I am using the following code to read and delete the messages... but this code does not actually delete messages:
public List<Sms> getAllSms() {
try {
List<Sms> lstSms = new ArrayList<Sms>();
Sms objSms = new Sms();
Uri uriSms = Uri.parse("content://sms/");
Cursor c = getActivity().getContentResolver().query(uriSms, new String[]{"_id", "thread_id", "address", "person", "date", "body"}, null, null, null);
getActivity().startManagingCursor(c);
int totalSMS = c.getCount();
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
String date = c.getString(3);
Log.e("log>>>",
"0--->" + c.getString(0) + "1---->" + c.getString(1)
+ "2---->" + c.getString(2) + "3--->"
+ c.getString(3) + "4----->" + c.getString(4)
+ "5---->" + c.getString(5));
Log.e("log>>>", "date" + c.getString(0));
if (address.equals("1234567890")) {
// mLogger.logInfo("Deleting SMS with id: " + threadId);
getContext().getContentResolver().delete(
Uri.parse("content://sms/" + id), null, null);
Log.e("log>>>", "Delete success.........");
}
c.moveToNext();
}
} else {
throw new RuntimeException("You have no SMS ");
}
c.close();
return lstSms;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Manifest permissions:
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
Please help me regarding to delete the messages.
OR
suggest me a way to do the following:
If I send message in background programatically in both the above Android version then it should not save messages in sent folder or anywhere in the device.
i want to delete message of particular contact number programmatically in android lollipop and marshmallow
You will need to write a complete SMS client.
You cannot implement an app that only deletes messages on API Level 19 and higher. The user will not make your app be the default SMS app on the device. If your app is not the default SMS app, then "your app is not able to write to the SMS Provider for other operations, such as to mark messages as draft, mark them as read, delete them, etc." See this official blog post for more.
Tell me the way that if i send message in background programatically in both the above android version. then it should not save in sent folder or anywhere in the device
The decision of what happens with sent SMS messages is made between Android, the user's default SMS client, and possibly the user. You do not get a vote.
I've wrote the following code, to get the whole conversation between the user and a number:
Uri SMS_INBOX = Uri.parse("content://sms/");
String selection = "thread_id = " + thread_id;
final String[] projection = new String[] { "*" };
Cursor c = getContentResolver().query(SMS_INBOX, projection, selection,null, "date");
startManagingCursor(c);
String[] body = new String[c.getCount()];
String[] address = new String[c.getCount()];
if (c.moveToFirst()) {
for (int j = 0; j < c.getColumnCount(); j++)
Log.w("ColumnName", c.getColumnName(j));
for (int i = 0; i < c.getCount(); i++) {
body[i] = c.getString(c.getColumnIndexOrThrow("body")).toString();
address[i] = c.getString(c.getColumnIndexOrThrow("address")).toString();
Log.d("address-" + i, address[i]);
Log.d("body-" + i, body[i]);
String subject = c.getString(c.getColumnIndexOrThrow("_id")).toString();
Log.d("_id-" + i, subject);
String thread = c.getString(c.getColumnIndexOrThrow("thread_id")).toString();
Log.d("thread_id-" + i, subject);
Log.d("----", "----");
c.moveToNext();
}
}
Via this code, i get all the messages in a conversation. The problem is, I can't figure out which number is sending which message. If i get the column "address" it returns the same number all the time (actually it returns the other person's number only), so I can't keep record of whether the message I just got through this code was sent by the user or the other number.
The column will always gives second persons number only.If you want to differentiate sent message and received message you have to use column 'type'.
body[i] = c.getString(c.getColumnIndexOrThrow("body")).toString();
if(c.getString(c.getColumnIndex("type")).equalsIgnoreCase("1")){
// sms received
msg_state[i]=1;
}
else {
//sms sent
msg_state[i]=0;
}
No You can easily identify the sent sms and received sms.
I want to delete some certain SMS automatically in my Android application. Therefore I have a method which does exactly what I want it to do. However, it only works if I deploy the application directly to my phone from Eclipse. Then it deletes incoming SMS. However, it does not work if the application is downloaded from the market. But there is also no error. Does anybody know how I can solve this or does this only work on rooted devices?
public void deleteSMS(Context context, String message, String number) {
try {
mLogger.logInfo("Deleting SMS from inbox");
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(uriSms,
new String[] { "_id", "thread_id", "address",
"person", "date", "body" }, null, null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
if (message.equals(body) && address.equals(number)) {
mLogger.logInfo("Deleting SMS with id: " + threadId);
context.getContentResolver().delete(
Uri.parse("content://sms/" + id), null, null);
}
} while (c.moveToNext());
}
} catch (Exception e) {
mLogger.logError("Could not delete SMS from inbox: " + e.getMessage());
}
}
Actually, the code in my post is 100% correct. The problem was that Android needs some time to store the SMS upon receiving it. So the solution is to just add a handler and delay the delete request for 1 or 2 seconds.
This actually solved the whole issue.
EDIT (thanks to Maksim Dmitriev):
Please consider that you can't delete SMS messages on devices with Android 4.4.
Also, the system now allows only the default app to write message data to the provider, although other apps can read at any time.
http://developer.android.com/about/versions/kitkat.html
No exception will be thrown if you try; nothing will be deleted. I have just tested it on two emulators.
How to send SMS messages programmatically
Please consider that you can't delete SMS messages on devices with Android 4.4.
Also, the system now allows only the default app to write message data
to the provider, although other apps can read at any time.
http://developer.android.com/about/versions/kitkat.html
No exception will be thrown if you try; nothing will be deleted. I have just tested it on two emulators.
How to send SMS messages programmatically
hey use this code to delete customize sms
1. By date
2. By number
3. By body
try {
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(
uriSms,
new String[] { "_id", "thread_id", "address", "person",
"date", "body" }, "read=0", null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
String date = c.getString(3);
Log.e("log>>>",
"0--->" + c.getString(0) + "1---->" + c.getString(1)
+ "2---->" + c.getString(2) + "3--->"
+ c.getString(3) + "4----->" + c.getString(4)
+ "5---->" + c.getString(5));
Log.e("log>>>", "date" + c.getString(0));
ContentValues values = new ContentValues();
values.put("read", true);
getContentResolver().update(Uri.parse("content://sms/"),
values, "_id=" + id, null);
if (message.equals(body) && address.equals(number)) {
// mLogger.logInfo("Deleting SMS with id: " + threadId);
context.getContentResolver().delete(
Uri.parse("content://sms/" + id), "date=?",
new String[] { c.getString(4) });
Log.e("log>>>", "Delete success.........");
}
} while (c.moveToNext());
}
} catch (Exception e) {
Log.e("log>>>", e.toString());
}
You can choose which app is the default SMS app in 4.4+ and if your app is set as the default it will be able to delete SMS as well.
to make app as default app see this.
Check if your app is default sms app before deleting.
Use the URI provided by telephony class instead of hardcoding.
public void deleteSMS(Context context,int position)
{
Uri deleteUri = Uri.parse(Telephony.Sms.CONTENT_URI);
int count = 0;
Cursor c = context.getContentResolver().query(deleteUri, new String[]{BaseColumns._ID}, null,
null, null); // only query _ID and not everything
try {
while (c.moveToNext()) {
// Delete the SMS
String pid = c.getString(Telephony.Sms._ID); // Get _id;
String uri = Telephony.Sms.CONTENT_URI.buildUpon().appendPath(pid)
count = context.getContentResolver().delete(uri,
null, null);
}
} catch (Exception e) {
}finally{
if(c!=null) c.close() // don't forget to close the cursor
}
}
it delete all(inbox,outbox,draft) the SMS.
private int deleteMessage(Context context, SmsMessage msg) {
Uri deleteUri = Uri.parse("content://sms");
int count = 0;
#SuppressLint("Recycle") Cursor c = context.getContentResolver().query(deleteUri, null, null, null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/" + pid;
count = context.getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
}
}
return count;
}
use this code.............
or
getContentResolver().delete(Uri.parse("content://sms/conversations/" + threadIdIn), null, null);
I was looking for a method to delete all SMS with one click. Thanks to this post I succeeded.
Here is my method if it interests someone :
private void deleteSMS(){
Uri myUri= Uri.parse("content://sms/");
Cursor cursor = getContext().getContentResolver().query(myUri, null,null,null,null);
while (cursor.moveToNext()) {
int thread_id = cursor.getInt(1);
getContext().getContentResolver().delete(Uri.parse("content://sms/conversations/" + thread_id),null,null);
}
cursor.close();
}
if you want get a message and your sms app your android device phone didn't send any notification use Binary (Data) SMS.