-2

I am developing an sms app. Now my app is default sms app on the phone. That means my app is receiving incoming sms first. Now I want to send incoming sms intent to other app (Built-in sms app) from my app pro-grammatically.

Note : I dont want to change default sms app.

My code to send broadcast from my app to built-in sms app --

 context.sendBroadcast(intent.setClassName( builtInSmsPackage, "com.android.mms.transaction.SmsReceiverService" )
.setPackage(builtInSmsPackage)
.setAction("android.provider.Telephony.SMS_RECEIVED"));

But built-in sms app cant receive the sms intent which i am sending from my app.

AGM Tazim
  • 2,213
  • 3
  • 16
  • 25
  • 1
    You don't need to. The system takes care of sending the `SMS_RECEIVED` broadcast to all the apps listening for it. Your default app doesn't have to do anything for that to happen. Do note, however, that dedicated SMS apps are expected to disable most of their functionality if they're not the default app, so it's probable that they won't be listening for that broadcast while your app is the default. – Mike M. Aug 21 '16 at 08:35
  • Its working fine till jelly-bean. But from kitkat its needed to make my app default sms app to receive sms. and then only my app can receive sms. No other can receive sms anymore while my app is default sms app. My code to send broadcast to default sms app is - context.sendBroadcast(intent.setClassName( builtInSmsPackage, "com.android.mms.transaction.SmsReceiverService" ) //.setPackage(builtInSmsPackage) .setAction("android.provider.Telephony.SMS_RECEIVED")); – AGM Tazim Aug 21 '16 at 10:00
  • 1
    "But from kitkat its needed to make my app default sms app to receive sms." - No, it's not. Your app doesn't have to be the default just to receive incoming SMS. Just register a Receiver for the `SMS_RECEIVED` action, and get the `RECEIVE_SMS` permission. "No other can receive sms anymore while my app is default sms app." - Yes, they can, but they're probably not listening for them. "My code to send broadcast..." - That's not going to work, because your app doesn't hold the necessary permission to broadcast to that Receiver. – Mike M. Aug 21 '16 at 10:17
  • Many many thanks for your comment. I have all permission required for sms in receiver. At first my app cant receive sms when it was not default sms app. But After making my app default sms app, its working fine. And here is link for making default sms app in kitkat--- http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html – AGM Tazim Aug 21 '16 at 10:25
  • And can you give me appropriate code for send brodacast to built-in sms app please? @ Mike M. – AGM Tazim Aug 21 '16 at 10:28
  • 1
    "I have all permission required for sms in receiver." - Your app may have the permissions necessary to receive SMS, but those aren't the same as the permission necessary to broadcast to built-in app's Receiver. "At first my app cant receive sms when it was not default sms app." - Then there was something wrong with your setup, because any app can receive SMS, if configured properly. "can you give me appropriate code for send brodacast to built-in sms app" - You can't. To broadcast to that Receiver requires the `BROADCAST_SMS` permission, which normal SDK apps cannot obtain. – Mike M. Aug 21 '16 at 10:32
  • 1
    Looking at your [previous question](http://stackoverflow.com/q/38975806), it appears that you're trying to create an SMS blocker. You can't really do that anymore, since KitKat, unless you're going to create a full-blown SMS client. I'm surprised CommonsWare didn't mention that. The default SMS app is responsible for many, many things. You can't set your app as the default, handle only what you want, and then try to pass off the rest of the duties to the platform app. SMS blocker apps are kind of a "thing of the past" in Android, for standard systems, anyway. – Mike M. Aug 21 '16 at 10:38
  • Did you read the post i linked you? I think there is huge change from kitkat and so on to receive sms. And finally what can i do for sending sms intent from my app to built-in sms app? – AGM Tazim Aug 21 '16 at 10:38
  • 1
    I am well aware of the current SMS API requirements and restrictions. You can't do what you're attempting to do. If you're creating a default SMS app, it needs to take care of composing, sending, and saving outgoing SMS, receiving and saving incoming SMS, handling MMS transactions, etc. It's not a trivial task. – Mike M. Aug 21 '16 at 10:40
  • @MikeM: Sorry, with the earlier question, I overlooked the opening sentence and did not realize that the OP is trying to create an SMS blocker. – CommonsWare Aug 21 '16 at 10:56
  • @CommonsWare Oh, hey. No worries. I kinda called ya out, there, didn't I? Apologies. Good point, in your answer, about that being a `Service`, not a Receiver. I didn't even really read that. I guess we're both guilty of glossing over stuff. :-) Cheers! – Mike M. Aug 21 '16 at 11:18

1 Answers1

3

Now my app is default sms app on the phone. That means my app is receiving incoming sms first.

SMS_RECEIVED broadcast order is determined by the priority on the <intent-filters>. SMS_DELIVER is only sent to one receiver, that of the user's chosen default SMS app.

My code to send broadcast from my app to built-in sms app --

First, that is the wrong Intent action. As Mike M. points out, the system will already provide the SMS to all SMS_RECEIVED broadcast receivers. That broadcast usually is ignored by the default SMS client (see the blog post that you claim to have read). The broadcast that is unique for the default SMS app is SMS_DELIVERED.

Second, you do not have rights to send SMS_DELIVER broadcasts. That requires holding the BROADCAST_SMS permission, which cannot be held by ordinary Android SDK apps, to prevent malware authors from doing what you are trying to do. Even with SMS_RECEIVED, I have been recommending that apps ensure that the sender holds BROADCAST_SMS for three years, again to combat malware.

Third, SmsReceiverService is a Service. You cannot send broadcasts to a service. That service may process the SMS_DELIVER broadcast, but it does not receive it.

Now I want to send incoming sms intent to other app

That is not possible on Android 4.4+ through standard Android SDK mechanisms. On Android 4.4+, SMS blocking is a feature of full SMS clients or the OS. It is not a feature that can be added by other apps.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491