Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive error message when trying to send a SMS using 'SMS Cordova plugin' #89

Open
Jaacov opened this issue Jul 9, 2023 · 2 comments

Comments

@Jaacov
Copy link

Jaacov commented Jul 9, 2023

I am trying to send a simple SMS with my Android phone (version 13) but receive the following error:

com.outsystemscloud.personaldu4qbox5.TestApp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.

Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

Anyone knows what could be the problem?

Kind regards,

Jaacov

@Camargo1958
Copy link

Camargo1958 commented Jul 9, 2023 via email

@MurageKabui
Copy link

  • If the plugin is already added to your project, remove it.

  • Navigate the source directory cordova-plugin-sms\src\android and open the file SMSPlugin.java.

  • Include import android.os.Build; among the other import statements/directives.

  • Modify the sendSMS Java function as follows:

private PluginResult sendSMS(JSONArray addressList, String text, CallbackContext callbackContext) {
        Log.d(LOGTAG, ACTION_SEND_SMS);
        if (this.cordova.getActivity().getPackageManager().hasSystemFeature("android.hardware.telephony")) {
            int n;
            if ((n = addressList.length()) > 0) {
                SmsManager sms = SmsManager.getDefault();
                for (int i = 0; i < n; ++i) {
                    String address = addressList.optString(i);
                    if (address.length() > 0) {
                        // Create a unique requestCode for each PendingIntent
                        int requestCode = (int) System.currentTimeMillis();
                        PendingIntent sentIntent = PendingIntent.getBroadcast(
                                (Context) this.cordova.getActivity(),
                                requestCode,
                                new Intent("SENDING_SMS"),
                                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
                        );

                        sms.sendTextMessage(address, null, text, sentIntent, null);
                    }
                }
                callbackContext.success("SMS sent successfully");
            } else {
                callbackContext.error("No valid recipients provided");
            }
        } else {
            callbackContext.error("SMS is not supported");
        }
        return null;
    }
  • Readd the plugin with changes into your project cordova plugin add pathtoplugin\cordova-plugin-sms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants