如何抑制新短信通知?

时间:2013-04-18 06:36:27

标签: java android notifications sms broadcastreceiver

我正在编写自己的短信使者,我需要完全禁止默认股票信使提出的新短信通知。我肯定会拦截收到的短信通知并通过Broadcast中止BroadcastReceiver.abortBroadcast(),例如:

public void onReceive(Context context, Intent intent) {
        Map<String, String> msgs = retrieveMessages(intent);
        for (String address : msgs.keySet()) {
            String msg = msgs.get(address);
            Log.i(TAG, "New sms received=" + msg);
            //saving message in phone
            Message message = Message.createIncomingMessage(address, msg);
            message.setSeen(1); ////mark message seen, so stock messenger couldn't arose notification
            message.setRead(1); //mark message read, so stock messenger couldn't report it as unread
            message.setUnread(true); //mark message unread for our messenger
            message = Me.getMe().getMessageDAO().save(context, message); //saving message 
            SmsReceiver.updateNotification(context, message, true, true); //raise notification from "our" messenger
        }
        //aborting default broadcast, since everything already done and no need to do more
        this.abortBroadcast();
    }

一切都按计划进行。但每当我在几秒钟内通过Me.getMe().getMessageDAO().save(context, message);将新短信插入数据库时​​,股票信息就会以某种方式通知数据库中的新消息并再次发出通知。

问题是:如何取消此通知?

1 个答案:

答案 0 :(得分:1)

首先,您需要设置接收方see docspriority

其次,在执行繁重的处理任务(存储到数据库)之前调用abortBroadCast

或者你可以在一个线程中尝试这个db存储事物,启动线程并立即调用abortBroadcast()