Android Question [SOLVED] Not Getting SMS Intents without SmsInterceptor

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Forgive me if I'm missing something obvious, but I'm attempting to implement the model Erel posted (here: https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/ and here https://www.b4x.com/android/forum/t...t-notification-android-4-4.37171/#post-227969) and I'm getting what I consider to be odd behavior.

I've added the manifest code for default messaging app and added the three services (right now the services just log the action and extras they receive).

If I do not create and initialize an SMSInteceptor in the service class I never see any of the intents come across to my class (i.e. my service_start never fires).

If, however, I create an SMSInterceptor object in the class and add a handler to use it, I see the intent come through to my class, and then the SMS_MessageReceived for the interceptor event fires. Relevant manifest code:
B4X:
SetReceiverAttribute(mqtextsmsr, android:permission, "android.permission.BROADCAST_SMS")
AddReceiverText(mqtextsmsr, <intent-filter>
  <action android:name="android.provider.Telephony.SMS_DELIVER" />
  </intent-filter>
)

SetReceiverAttribute(mqtextmmsr, android:permission, "android.permission.BROADCAST_WAP_PUSH")
AddReceiverText(mqtextmmsr,  <intent-filter>
  <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
  <data android:mimeType="application/vnd.wap.mms-message" />
  </intent-filter>
)

SetServiceAttribute(mqtextrespondvia, android:permission, "android.permission.SEND_RESPOND_VIA_MESSAGE")
SetServiceAttribute(mqtextrespondvia, android:exported, "true")
AddServiceText(mqtextrespondvia,  <intent-filter>
  <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="sms" />
  <data android:scheme="smsto" />
  <data android:scheme="mms" />
  <data android:scheme="mmsto" />
  </intent-filter>
)

AddActivityText(main,
<intent-filter>
  <action android:name="android.intent.action.SEND" />  
  <action android:name="android.intent.action.SENDTO" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="sms" />
  <data android:scheme="smsto" />
  <data android:scheme="mms" />
  <data android:scheme="mmsto" />
  </intent-filter>
)

I thought if your app is acting as the default messaging app you could just handle everything through the classes and not have to use an SmsInterceptor object?
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
If you are speaking of the receive intent:
B4X:
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(s1, 
<intent-filter>
 <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
I did have it in at one point, but when I do manage to receive intents the "SMS_DELIVERED" intent fires, then the "SMS_RECEIVED" intent fires. As I understood the Android documentation, only the "default" app will get the _DELIVERED intent and all other registered apps will get the _RECEIVED intent.

Even with that intent in the manifest I still am not getting any intents at all if I do not instantiate an SmsIntercecptor object, which confuses me (far more than normal ).
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Ok, I think I've got most of it sorted...

I needed the "AddPermission(android.permission.RECEIVE_SMS)" bit but not the intent filter for received (since I'm the default app I will get the _DELIVERED intent) it seems I took out the permission when I removed the intent. Once I added the permission back in I started receiving the events without the SmsInterceptor (it seems that object must add the permission automagically when you use it).

Thank you for your help!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…