Android: java.lang.SecurityException: Package com.android.phone (uid=1001) does not match provided uid 10246
Asked Answered
L

2

7

Scenario: We are sending SMS to particular number if user grantees the SMS permission.

Devices: Only Samsung devices with Android 11.

Code:

SmsManager.getSmsManagerForSubscriptionId(subscriptionId)
.sendTextMessage(destinationAddress, null, getString(R.string.xyz)
.format(token), sendSMSPendingIntent, null)

Exception:

java.lang.SecurityException: Package com.android.phone (uid=1001) does not match provided uid 10246

android.os.Parcel.createExceptionOrNull Parcel.java:2385
android.os.Parcel.createException Parcel.java:2369
android.os.Parcel.readException Parcel.java:2352
android.os.Parcel.readException Parcel.java:2294
com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber ISms.java:2102
android.telephony.SmsManager$1.onSuccess SmsManager.java:618
android.telephony.SmsManager.sendResolverResult SmsManager.java:1627
android.telephony.SmsManager.resolveSubscriptionForOperation SmsManager.java:1588
android.telephony.SmsManager.sendTextMessageInternal SmsManager.java:613
android.telephony.SmsManager.sendTextMessage SmsManager.java:451```
Logogram answered 17/11, 2021 at 10:54 Comment(1)
Can you update the question to include the specific SMS permission the user granted?Tetany
L
2

Found the root cause.

When SIM card is inactive then device may throw the Security exception.

Solution: Just replace with working SIM card.

Hope it helps.

Logogram answered 24/1, 2023 at 10:1 Comment(0)
P
4

You have to check the airplane mode status and mobile network status before trying to send sms.

Skip send sms call and show error message if airplane mode is enable or signal strength is zero.

Check airplane mode:

public static boolean isAirplaneModeOn(Context context) {
       return Settings.System.getInt(context.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}

check mobile network

@RequiresApi(api = Build.VERSION_CODES.P)
public static boolean isNoSignalStrength(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    return telephonyManager.getSignalStrength().getLevel() == 0;
}

I got the solution from this link https://askandroidquestions.com/2021/08/04/samsung-android-11-java-lang-securityexception-package-com-android-phone-uid1001-does-not-match-provided-uid-10571/?unapproved=6705&moderation-hash=ad920e86b8ab19ada9b29f39694490d5#comment-6705

Putative answered 28/12, 2021 at 5:54 Comment(2)
Is this a common issue with Samsung devices? The URL you provided is not currently working.Grozny
Yes, Samsung updated os code for android 11 or higher. Other OEM devices don't throw any exception on send sms failure due to network strength. I am not sure why url is not working but you can try above code to fix the problem.Putative
L
2

Found the root cause.

When SIM card is inactive then device may throw the Security exception.

Solution: Just replace with working SIM card.

Hope it helps.

Logogram answered 24/1, 2023 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.