阻止发来的短信被登录的默认短信应用 [英] Block sent SMS from being logged in default messaging app

查看:694
本文介绍了阻止发来的短信被登录的默认短信应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自动回复短信Android应用我建,我不希望自动回复(短信发送)在默认消息应用展示。我已经搜查,搜查,但没有找到答案。有没有一种方法可以绕过编写短信发送到默认的消息应用程序?

下面我BroadcastReciever我使用来获取数据并发送出消息

 公共类SmsReceiver扩展广播接收器{ParseUser用户= ParseUser.getCurrentUser();
从企业目前的答复和url组成//自动回复消息
串味精= user.getString(myCurrentReply)++ user.getString(couponUrlChosen);列表smsFromList = user.getList(smsFrom);
字符串username =(字符串)user.get(用户名);@覆盖
公共无效的onReceive(最终上下文的背景下,意图意图){
    捆绑包= intent.getExtras();    对象信息[] =(Object []对象)bundle.get(的PDU);
    SmsMessage smsMessage [] =新SmsMessage [messages.length]
    对于(INT N = 0; N< messages.length; N ++){
        smsMessage [η] = SmsMessage.createFromPdu((字节[])消息[N]);
    }
    最后弦乐PNO = smsMessage [0] .getOriginatingAddress();
    user.put(lastSmsFrom,PNO);
    user.saveInBackground();    //显示第一条消息
    吐司面包= Toast.makeText(背景下,收到的短信:+ smsMessage [0] .getMessageBody(),Toast.LENGTH_LONG);
    toast.show();    //从短信用户收到的排阵对检查电话号码
    ParseQuery<&的parseObject GT;查询= ParseQuery.getQuery(_用户);    Log.d(用户名:用户名);
    query.whereEqualTo(用户名,用户名);
    query.whereContainedIn(lastSmsFrom,smsFromList);
    query.findInBackground(新FindCallback<&的parseObject GT;(){
        公共无效完成(列表<&的parseObject GT; smsList,ParseException的E){
            如果(E == NULL){
                Log.d(错误,无);
                如果(smsList.size()== 0){
                    //发送短信
                    sendSms(PNO,味精);                    //添加电话号码smsFrom在currentUsers行
                    user.addUnique(smsFrom,PNO);                    在阵列//保存电话号码
                    user.saveInBackground();                    Log.d(列出的大小:,+ smsList.size());
                }
            }其他{
                Log.d(错误消息:
                        e.getMessage());
            }
            Log.d(今天已经发送到该号码。,+ smsList.size());
        }
    });}私人无效sendSms(字符串PHONENUMBER,字符串消息){    SmsManager经理= SmsManager.getDefault();
    manager.sendTextMessage(PHONENUMBER,空,消息,NULL,NULL);}
 }


解决方案

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

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

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


* 中有4.4安全漏洞的只有的,其中非默认的应用程序可以获取对供应商进行写访问。它是在<一个详细href=\"http://stackoverflow.com/questions/27697282/android-kitkat-api-19-how-to-write-messages-in-sms-content-provider-without/27709655#27709655\">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.

这篇关于阻止发来的短信被登录的默认短信应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆