隐藏短信通知,在奇巧一个BroadcastReceiver奇巧、短信、通知、BroadcastReceiver

2023-09-05 05:16:52 作者:不知该叫啥

我想利用广播接收器拦截收到的短信。这里是code:

I'm trying to intercept the received SMSs by using a broadcast receiver. Here is the code:

    <receiver android:name=".receivers.SmsReceiver" android:enabled="true"
        android:exported="true" android:priority="999">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

public class SmsReceiver extends BroadcastReceiver {
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

@Override
public void onReceive(Context context, Intent intent) {
    if (SMS_RECEIVED.equals(intent.getAction())) {
        this.abortBroadcast();

        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            // get sms objects
            Object[] pdus = (Object[]) bundle.get("pdus");
            if (pdus.length == 0) {
                return;
            }
            // large message might be broken into many
            SmsMessage[] messages = new SmsMessage[pdus.length];
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < pdus.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                sb.append(messages[i].getMessageBody());
            }
            String sender = messages[0].getOriginatingAddress();
            String message = sb.toString();

            Log.d("sms", sender);
            Log.d("sms", message);
        }
    }
}
}

该短信​​被拦截罚款,但普通的​​Andr​​oid手机短信的应用程序仍显示出其的通知,我还可以找到股票的应用程序短信列表内的信息。

The SMS is intercepted fine, but the stock Android SMS app is still showing its notifications and I can also find the message inside the stock app sms list.

有没有办法阻止股票SMS应用程序通知和避免消息出现的列表里?

Is there any way to stop the stock SMS app notifications and to avoid the message from appearing inside its list?

推荐答案

如果用户设置应用程序为默认的短信应用程序,那么他/她是不是会得到短信通知。你必须处理的通知,以及短信在你的应用程序的其他功能。

If user has set your application as default SMS app, then he/she is not going to get an SMS notification. You have to handle the notification, as well as other feature of the SMS in your app.

有关详细信息,阅读这个博客。

查看其他博客和的示例应用程序。

 
精彩推荐
图片推荐