Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);

}
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
152 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...