gpt4 book ai didi

java - 尽管优先级设置为最高,但在 Android 4.4 及更高版本上消息不会被阻止。有解决方法吗?

转载 作者:行者123 更新时间:2023-12-01 11:51:58 25 4
gpt4 key购买 nike

阻止短信,但它似乎不适用于 Android 版本 4.4 及更高版本。 Stackoverflow 上的其他地方已经对此进行了讨论,但到目前为止还没有已知的解决方法。有什么办法可以使优先级高于默认短信应用程序吗?这是我使用的代码:

    if (MSG_TYPE.equals("android.provider.Telephony.SMS_RECEIVED")) {
// Toast toast = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);
// toast.show();

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]);
}
String body = smsMessage[0].getMessageBody().toString();
String num = smsMessage[0].getOriginatingAddress().toString();
try {
for (String a : mBlackList) {
if (PhoneNumberUtils.compare(a, num)) {
abortBroadcast();
if (preferences.getBoolean("show_notif", true)) {
showNotification(num, body);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

最佳答案

这是由于 4.4 中 SMSProvider 的更改所致。要中止广播,您的应用程序必须注册为“默认短信应用程序”。

Other apps that are not selected as the default SMS app can only read the SMS Provider, but may also be notified when a new SMS arrives by listening for the SMS_RECEIVED_ACTION broadcast, which is a non-abortable broadcast that may be delivered to multiple apps. This broadcast is intended for apps that---while not selected as the default SMS app---need to read special incoming messages such as to perform phone number verification.

https://developer.android.com/about/versions/android-4.4.html#SMS

有关设置为默认短信应用程序的详细信息:

http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

关于java - 尽管优先级设置为最高,但在 Android 4.4 及更高版本上消息不会被阻止。有解决方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28731477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com