2

I'm developing an app that listens to incoming SMS. Everything is working fine, but the problem is in onReceive() method of Broadcast receiver, it is also receiving the SIM card's push (Class 0) messages (like balance info / SMS remaining, etc which comes as pop up after sending an SMS or making a call).

I want to handle only the SMS messages in that method. Is there any check by which I can distinguish between these messages in onReceive()?

Vishal Afre
  • 1,013
  • 3
  • 12
  • 39
  • use action in your intent filter of broadcast receiver and check the action while receiving message – Shalu T D May 27 '20 at 06:44
  • action is `android.provider.Telephony.SMS_RECEIVED` in both the cases as I've set this action only in Manifest in the receiver – Vishal Afre May 27 '20 at 06:52
  • 1
    If they are indeed coming through as class zero SMS, the `SmsMessage` class has [the `getMessageClass()` method](https://developer.android.com/reference/android/telephony/SmsMessage#getMessageClass()) that I believe you can check to see if it's `== SmsMessage.MessageClass.CLASS_0`. – Mike M. May 27 '20 at 07:04

0 Answers0