问题
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.
回答1:
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" />
回答2:
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.
来源:https://stackoverflow.com/questions/15217715/how-to-send-sms-from-the-android-app-without-making-its-record-in-device-sms-vie