Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send SMS from the Android app without making its record in device SMS view?

Tags:

android

sms

I want to send an SMS from my android app. But I don't want its record to be exist in device message view. I am currently using below code.

sendSMS(etsendernumber.getText().toString(), etmessagebody.getText().toString()); 
sendintent = new Intent(Intent.ACTION_VIEW);
sendintent.putExtra("sms_body","");
sendintent.setType("vnd.android-dir/mms-sms");
startActivity(sendintent);

But it is making sent sms record in message view of the device. Can we send a secret sms from android application?

Please advice.

like image 723
Sanchit Paurush Avatar asked Mar 05 '13 07:03

Sanchit Paurush


People also ask

How do I change SMS permission on Android?

In some versions of Android, this permission is turned on by default. In other versions, this permission is turned off by default. To set the app's permission on a device or emulator instance, choose Settings > Apps > SMS Messaging > Permissions, and turn on the SMS permission for the app.

How can I read SMS messages from the device programmatically in Android?

parse("content://sms/inbox"); // List required columns String[] reqCols = new String[]{"_id", "address", "body"}; // Get Content Resolver object, which will deal with Content Provider ContentResolver cr = getContentResolver(); // Fetch Inbox SMS Message from Built-in Content Provider Cursor c = cr.

How SMS can be sent from a smart phone Android code?

The following code shows how you can invoke the built-in SMS application to help you send an SMS message: Intent sendIntent = new Intent(Intent. ACTION_VIEW); sendIntent. putExtra("sms_body", "Content of the SMS goes here..."); sendIntent.


2 Answers

Yes, the way you are trying to send SMS is by using the shipped messaging application. So it will always record the sent messages. You must use SmsManager to send the SMS.

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);

In this way, your SMS wont be inserted into the list.

Also remember to add this in your manifest

<uses-permission android:name="android.permission.SEND_SMS" />
like image 103
Royston Pinto Avatar answered Oct 06 '22 07:10

Royston Pinto


If you use android SMS application to send message then it would save that message in the outbox or sent. What you can do is delete that message from the sms database. After sending sms Delete that message using this:

getContentResolver().delete(Uri.parse("content://sms/outbox"), "address = ? and body = ?", new String[] {etsendernumber.getText().toString(),etmessagebody.getText().toString()});

If msg is in out box

OR

getContentResolver().delete(Uri.parse("content://sms/sent"), "address = ? and body = ?", new String[] {etsendernumber.getText().toString(),etmessagebody.getText().toString()});

If message is in sent items.

like image 29
AnujMathur_07 Avatar answered Oct 06 '22 05:10

AnujMathur_07