Search code examples
androidandroid-6.0-marshmallowandroid-permissionsandroid-4.4-kitkatsmsmanager

Android - Broadcast SMS intent to other (Biult-in sms app) app in android


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.


Solution

  • 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.