The app uses SmsManager to send SMS text messages. The following method is only called after the SEND_SMS runtime permission has been successfully acquired from the user. The app targets API 25.
public static void sendSmsTextMessage(Context context, String number, String message) {
SmsManager sms = SmsManager.getDefault();
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS);
if (permissionCheck == PERMISSION_DENIED) {
Timber.e("Permission to send SMS denied");
} else {
sms.sendTextMessage(number, null, message, null, null);
}
}
Until now it had worked fine on all the devices it has been tested on. But it has now been used on a phone, the Logicom L-EMENT 553, and the app blows up when trying to call sendTextMessage() on API 23 (Marshmallow) with this exception:
Exception java.lang.RuntimeException: Failure delivering result
ResultInfo{who=@android:requestPermissions:, request=1, result=-1,
data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has
extras) }} to activity
{com.myapp.android/com.myapp.android.ui.bet.BetActivity}:
java.lang.SecurityException: Neither user 10108 nor current process
has android.permission.READ_PHONE_STATE.
Why would the READ_PHONE_STATE permission be required on some devices, but not others when sending SMS messages? Obviously it is preferable to not request this permission as it is a big ask of the user to provide this level of access.
The answers to a question here Why would sendTextMessage require READ_PHONE_STATE permission? suggest some Android versions contain a bug that requests this permission, but is it that or that the sendTextMessage() method was passed a message over the length limit, and then went on to split it using divideMessage() which then requests this permission? Although having said that I see no evidence sendMessage() automatically splits long messages into smaller pieces and sends them.
divideMessage()
runs fine withoutREAD_PHONE_STATE
, butsendMultipartTextMessage()
does require it. See #46421912 – Committal