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

╄→гoц情女王★ 提交于 2019-12-12 08:30:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!