πŸ“¨ "SEND_SMS" or Intent.ACTION_SENDTO Permission Not Allowed in App - Android OS 15

 In Android 15 (API level 34), the SEND_SMS permission is restricted for most apps. This change is part of Google's security enhancements to prevent misuse and protect user privacy.

πŸ”Ž Why You See This Error

  • Restricted Permissions: Starting from Android 15, only default SMS apps or apps granted special carrier privileges can request the SEND_SMS permission.

  • Non-Default Apps: If your app is not the system's default SMS app, it cannot send SMS using the SmsManager or Intent.ACTION_SENDTO.


βœ… Solutions and Workarounds

Here are a few options depending on your app's needs:

1. Check if Your App is the Default SMS App

  • If your app is a messaging app, request users to set it as the default SMS app using this intent:


Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName()); startActivity(intent);

2. Use SMS Verification API (For OTPs)

  • If you're sending SMS for OTP verification, use SMS Retriever API instead. This API doesn't need SEND_SMS permission.

  • Learn about SMS Retriever API

3. Use Intent to Open SMS App

  • You can prompt the user to send a pre-filled SMS using the default messaging app:


Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto:" + phoneNumber)); intent.putExtra("sms_body", "Your verification code is: 123456"); startActivity(intent);
  • No Permission Required with this method.


πŸš€ Additional Tips

  • If you're a carrier app or have special privileges, ensure proper configurations in the manifest using:


<uses-permission android:name="android.permission.SEND_SMS"/>
  • Contact your carrier provider if your app qualifies for carrier-specific permissions.


Solution 1:

If your app is not the default SMS app, Android 15 restricts the SEND_SMS permission. However, here are a few alternative solutions you can implement:


βœ… Solution 1: Use ACTION_SENDTO for User-Initiated SMS

  • You can use an Intent to open the default SMS app with a pre-filled message.

  • This does not require the SEND_SMS permission.

πŸ“¦ Example Code

java
Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto:" + phoneNumber)); // Replace phoneNumber with the actual number intent.putExtra("sms_body", "Your verification code is: 123456"); startActivity(intent);
  • The user will see the SMS app with the message ready to send.

  • No additional permissions are required.


βœ… Solution 2: Use Web APIs or External SMS Gateways

  • If your app needs to send SMS without relying on the device, consider using an SMS Gateway or an API like:

    • Twilio

    • Plivo

    • Nexmo (Vonage)

  • Your backend can handle sending SMS using these services.

πŸ“¦ Example Flow

  1. App requests SMS to be sent β†’

  2. API call to your backend β†’

  3. Backend sends SMS using the gateway.


βœ… Solution 3: Use SMS Retriever API for OTPs (No SMS Permission Required)

If you're using SMS for OTP verification, use the SMS Retriever API.

  • No SEND_SMS or RECEIVE_SMS permission is needed.

  • Android automatically captures the OTP from the SMS for verification.

πŸ“¦ Example Flow

  1. App starts the SMS Retriever API.

  2. Backend sends an SMS with a verification code.

  3. The API captures the SMS without the user needing to copy the code manually.


βœ… Solution 4: Use Carrier Privileges (For Carrier Apps Only)

  • If your app is provided by a mobile carrier or has special agreements, you can request carrier privileges.

  • This requires signing your app with the carrier’s certificate and using the SEND_SMS permission.


πŸš€ Recommendation

  • For General Apps: Use Solution 1 (Intent-based) for a seamless experience.

  • For OTP Verification: Use Solution 3 (SMS Retriever API).

  • For Business or Automated Messages: Use Solution 2 with an SMS Gateway.


Comments

Popular posts from this blog

Your build is currently configured to use incompatible Java 21.0.3 and Gradle 8.2.1. Cannot sync the project.

Google Assistant Implementation in Android application with app actions