Deleting SMS Using BroadCastReceiver - Android

前端 未结 2 2103
忘掉有多难
忘掉有多难 2021-01-03 14:02

i have broadcast receiver class for receiving sms, but i dont know how to delete the received sms before reaching to the inbox as well as the notification

相关标签:
2条回答
  • 2021-01-03 14:29
    <receiver android:name=".SMSReceiver"
             android:permission="android.permission.BROADCAST_SMS"> 
            <intent-filter android:priority="999" > 
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
    </receiver>
    

    and in receiver

      public void onReceive(Context context, Intent intent) {
         //... 
         abortBroadcast();
       }
    

    This will work fine.

    0 讨论(0)
  • 2021-01-03 14:41

    In your intent filter you should set the priority higher than the systems SMS-application.

    <intent-filter android:priority="100" ...

    And then in your broadcast receiver you call abortBroadcast()

       public void onReceive(Context context, Intent intent) {
         //... 
         abortBroadcast();
       }
    
    0 讨论(0)
提交回复
热议问题