Sending SMS in newer (API 36.1-ish) versions of Android


TL;DR: How to bypass recent limitations on what apps can send messages without being the Default SMS app?

I am trying to build an Android app (MinAPILevel: 24. TargetAPILevel: 36) that needs to send messages, and I'm using the SMSManager given by the getDefault() method of the class. I am now aware that newer versions of Android only allow the default SMS app to send messages, but I assumed at first that that was a limitation only for Google Play Store apps, and not enforced on the device level.

All tutorials that I have found on the subject are either old, unspecific, or don't cover this specific case

Regardless, the app crashes when it tries to send a message. Here is the stack trace:

Process: xyz.Pangea.smsforwarder, PID: 19038 java.lang.RuntimeException: Unable to start receiver xyz.Pangea.smsforwarder.SMSListener: java.lang.SecurityException: Sending SMS message: uid 10218 does not have android.permission.SEND_SMS. at android.app.ActivityThread.handleReceiver(ActivityThread.java:5672) at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2904) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loopOnce(Looper.java:273) at android.os.Looper.loop(Looper.java:363) at android.app.ActivityThread.main(ActivityThread.java:10060) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) Caused by: java.lang.SecurityException: Sending SMS message: uid 10218 does not have android.permission.SEND_SMS. at android.os.Parcel.createExceptionOrNull(Parcel.java:3354) at android.os.Parcel.createException(Parcel.java:3338) at android.os.Parcel.readException(Parcel.java:3321) at android.os.Parcel.readException(Parcel.java:3263) at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:1976) at android.telephony.SmsManager$1.onSuccess(SmsManager.java:768) at android.telephony.SmsManager.sendResolverResult(SmsManager.java:1818) at android.telephony.SmsManager.resolveSubscriptionForOperation(SmsManager.java:1779) at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:763) at android.telephony.SmsManager.sendTextMessage(SmsManager.java:596) at xyz.Pangea.smsforwarder.SMSListener.onReceive(SMSListener.kt:54) at android.app.ActivityThread.handleReceiver(ActivityThread.java:5663) ... 9 more

The AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <uses-feature android:name="android.hardware.telephony" android:required="false" /> <uses-permission android:name="android.permission.RECEIVE_SMS" tools:ignore="SmsAndCallLogPolicy" /> <uses-permission android:name="android.permission.SEND_SMS" tools:ignore="SmsAndCallLogPolicy" /> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SMSForwarder"> <receiver android:exported="true" android:enabled="true" android:name="xyz.Pangea.smsforwarder.SMSListener" android:permission="android.permission.BROADCAST_SMS"> <intent-filter android:priority="2147483647"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

Note that receiving messages works perfectly fine.

Also note that in the settings of the test phone, the app has SMS permissions set (for whatever reason, no distinction is made between sending and receiving messages).

Is there a way to ignore this? I know you can use Intent to send messages with the default SMS application, but that is disruptive, and I'd rather it be done in the background.

Some suggestions I anticipate:

  1. Why not use existing apps?

    Existing apps either make you log in or sign up to some service.

  2. Open source versions of those exist

    I want to build my own.

  3. You can't publish your app on the Play Store if you break this policy.

    This app will not be put on the Google Play Store, and it is very unlikely that I will even open source it. I am making the app for private use.

0
May 27 at 12:07 PM
User AvatarGooseyLoosey
#android#sms#android-permissions

No answer found for this question yet.