如何防止短信进入 Android Kitkat 中的收件箱 [英] How to prevent SMS going to inbox in Android Kitkat

查看:50
本文介绍了如何防止短信进入 Android Kitkat 中的收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以前的安卓版本中,我们可以使用以下代码阻止短信:

In previous versions of android we could block SMS by using following code:

 <receiver android:name=".broadcastreceivers.OnSMSReceived"
                  android:exported="true" android:permission="android.permission.BROADCAST_SMS">

            <intent-filter android:priority="1000">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>

在广播接收器中,abortBroadcast() 函数阻止短信进入收件箱.但是这种方法在 kitkat 中不起作用,因为来自 Kitkat 的 SMS 只会被默认的 SMS 应用程序接收.是否有任何解决方法可以在 kitkat 中创建短信拦截器应用程序?

and in broadcast receiver, abortBroadcast() function prevent SMS from going to inbox. But this method is not working in kitkat as, from Kitkat SMS will only be received by default SMS app. Is there any workaround to create SMS blocker app in kitkat?

推荐答案

您应该阅读此页面:http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

KitKat 中引入了一项更改,一次仅允许一个应用程序(默认 SMS 应用程序)拥有对 SMS 数据库的写入权限并能够使用它.

A change was introduced in KitKat that only allows one application at a time (the default SMS app) to have write permissions on the SMS DB and to be able to consume it.

您有两种解决问题的方法:

You have 2 ways of solving your problem:

  • 按照 Google 的建议,在您需要执行更改时,如何请求用户将默认 SMS 应用程序切换到您的应用程序(完成更改后,允许用户切换回您的应用程序)原始默认短信应用).

  • Follow Google advice on how to request the user to switch the default SMS application to your application during the time when you need to perform your changes (and once you finish doing it, allow the user to switch back to the original default SMS app).

找到一种临时的hacky方式来做你需要做的事情.作为提示,有一个隐藏的 API:AppOpsManager#setMode,您可以按顺序利用它要授予您的应用程序写入权限 (OP_WRITE_SMS),请访问此 XDA 页面以了解更多信息:http://forum.xda-developers.com/showthread.php?t=2551072

Find a temporary hacky way to do what you need to do. As a hint, there is a hidden API: AppOpsManager#setMode that you could potentially exploit in order to give your application write permissions (OP_WRITE_SMS), head over to this XDA page to learn more about it: http://forum.xda-developers.com/showthread.php?t=2551072

不用说,任何 hacky 解决方案都只是暂时的,因为私有/隐藏 API 可能随时更改.强烈鼓励实施 Google 建议我们实施的内容,再次描述 此处.

Needless to say, any hacky solution is just temporary as a private/hidden API could change at any moment. It is strongly encouraged to implement what Google advised us to implement which again is described here.

这篇关于如何防止短信进入 Android Kitkat 中的收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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