SMS Received in my SMS app and in Hangouts, although I call abortBroadcast()

南楼画角 提交于 2019-11-29 10:18:34

问题


I have an SMS blocker Android application developed myself which was working quite well capturing all the spams until recently Google updated its Hangouts app to work with SMSs.

The Problem: SMS is getting captured by both my app and hangouts! Even though the message is blocked by my app and stored in its private database, it is also present in the hangouts app and thus in the stock Messaging app at the same time.

Seems the abortBroadcast() isn't working any more. Everything was working perfectly before the Hangouts update.

I had also tried fiddling with android:priority but in vain.


回答1:


Hangouts uses the maximum possible priority (999 per the Intent-Filter docs) and therefore you cannot abort it on <4.4 releases. On 4.4+, only the default SMS app (blog post with details) can receive SMS notifications - users would need to set your app as the default SMS app for your app to function correctly (although it should function as expected if that happens).




回答2:


When you register receiver, set priority of filter to INTEGER.MAX_VALUE. Now abortBroadcast() will work;

    receiver = new HightPrioritySmsReceiver();
    IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    filter.setPriority(Integer.MAX_VALUE);
    registerReceiver(receiver, filter);


来源:https://stackoverflow.com/questions/20027658/sms-received-in-my-sms-app-and-in-hangouts-although-i-call-abortbroadcast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!