且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

阻止发来的短信被登录的默认短信应用

更新时间:2023-01-06 12:18:03

在此之前奇巧,短信使用 SmsManager 要求应用程序将消息发送到其插入提供商发送,所以它也只是省略了的问题。

与奇巧,任何应用程序,是不是默认的短信应用和用途启动 SmsManager 来发送消息都将自动写入到系统中的供应商为它的消息。有没有办法为prevent这一点,并且,此外,该应用程序将无法删除这些邮件,或者,因为它不会有对供应商的写入权限。 *

该应用程序是默认的短信应用是负责撰写其传出消息,所以它能够省略这一步。该系统不会进行自动写入默认的短信应用。


* 中有4.4安全漏洞的只有的,其中非默认的应用程序可以获取对供应商进行写访问。它是在my回答这里,但奇巧后,它不会在版本。

I have an auto reply sms Android application I built and I don't want the auto reply (sent sms) to show in the default messaging app. I have searched and searched and couldn't find an answer. Is there a way to bypass writing the sent sms into the default messaging app?

Here my BroadcastReciever I am using to get the data and send out the message

public class SmsReceiver extends BroadcastReceiver {

ParseUser user = ParseUser.getCurrentUser();
// Auto reply message composed of the current reply and url from that business
String msg = user.getString("myCurrentReply") + " " + user.getString("couponUrlChosen");

List smsFromList = user.getList("smsFrom");
String userName = (String) user.get("username");

@Override
public void onReceive(final Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    Object messages[] = (Object[]) bundle.get("pdus");
    SmsMessage smsMessage[] = new SmsMessage[messages.length];
    for (int n = 0; n < messages.length; n++) {
        smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
    }
    final String pno = smsMessage[0].getOriginatingAddress();
    user.put("lastSmsFrom", pno);
    user.saveInBackground();

    // show first message
    Toast toast = Toast.makeText(context, "Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
    toast.show();

    // Check Phone Number from SMS Received against Array in User Row
    ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");

    Log.d("Username: ", userName);
    query.whereEqualTo("username", userName);
    query.whereContainedIn("lastSmsFrom", smsFromList);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> smsList, ParseException e) {
            if (e == null) {
                Log.d("Errors", "none");
                if (smsList.size() == 0) {
                    // Send SMS
                    sendSms(pno, msg);

                    // Add Phone number to smsFrom in currentUsers Row
                    user.addUnique("smsFrom", pno);

                    // Save Phone Number in Array
                    user.saveInBackground();

                    Log.d("List size: ", " " + smsList.size());


                }
            } else {
                Log.d("Error Message: ",
                        e.getMessage());
            }
            Log.d("Already sent to this number today. ", " " + smsList.size());
        }
    });

}

private void sendSms(String phonenumber, String message) {

    SmsManager manager = SmsManager.getDefault();
    manager.sendTextMessage(phonenumber, null, message, null, null);

}
 }

Prior to KitKat, SMS sent using SmsManager require the app sending the message to insert it into the Provider, so it would just be a matter of omitting that.

Starting with KitKat, any app that is not the default SMS app and uses SmsManager to send messages will have the messages automatically written to the Provider for it by the system. There's no way to prevent this, and, furthermore, the app won't be able to delete those messages, either, as it won't have write access to the Provider.*

The app that is the default SMS app is responsible for writing its outgoing messages, so it would be able to omit that step. The system does no automatic writes for the default SMS app.


* There is a security hole in 4.4 only, by which a non-default app can gain write access to the Provider. It is detailed in my answer here, but it will not work in versions after KitKat.