如何在Java中sendmultiparttextmessage

发布于 2025-02-09 21:29:48 字数 2183 浏览 0 评论 0原文

我正在尝试修改现有插件以启用其发送长短信。我对Java并不熟悉,但是我在网上找到了一些示例并跟随了它们。但是,我遇到了一个错误不兼容的类型:sendsmsmodule不能转换为上下文triveedpiarr.add(pendingIntent.getBroadcast(this,0,new Intent(exterveed),0),0));

不兼容的类型:sendsmsmodule不能转换为上下文sentpiarr.add(pendingIntent.getBroadcast(this,0,new Intent(send),0),0));

这是我的Java代码

private void sendDirect(ReadableMap options, Callback callback) {

        String msg = options.hasKey("body") ? options.getString("body") : "";
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
                new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                new Intent(DELIVERED), 0);

        ReadableArray recipients = options.hasKey("recipients") ? options.getArray("recipients") : null;
        for (int i = 0; i < recipients.size(); i++) {
            String phoneNo = recipients.getString(i);
            try {
                SmsManager smsManager = SmsManager.getDefault();
                if (msg.length() > 160) {
                    ArrayList<String> parts = smsManager.divideMessage(msg);

                    ArrayList<PendingIntent> sentPIarr = new ArrayList<PendingIntent>();
                    ArrayList<PendingIntent> deliveredPIarr = new ArrayList<PendingIntent>();

                    for (int m = 0; m < parts.size(); m++) {
                        sentPIarr.add(PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0));
                        deliveredPIarr.add(PendingIntent.getBroadcast(this, 0,new Intent(DELIVERED), 0));
                    }

                    smsManager.sendMultipartTextMessage(phoneNo, null, parts, sentPIarr, deliveredPIarr);
                } else {
                    smsManager.sendTextMessage(phoneNo, null, msg, null, null);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                sendCallback(false, false, true);
                return;
            }
        }

        sendCallback(true, false, false);

    }
}

i'm trying to modify an existing plugin to enable it send long text messages. I am not so familiar with java, but I found some examples online and followed them. However i'm getting an error incompatible types: SendSMSModule cannot be converted to Context deliveredPIarr.add(PendingIntent.getBroadcast(this, 0,new Intent(DELIVERED), 0));

incompatible types: SendSMSModule cannot be converted to Context sentPIarr.add(PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0));

This is my java code

private void sendDirect(ReadableMap options, Callback callback) {

        String msg = options.hasKey("body") ? options.getString("body") : "";
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
                new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                new Intent(DELIVERED), 0);

        ReadableArray recipients = options.hasKey("recipients") ? options.getArray("recipients") : null;
        for (int i = 0; i < recipients.size(); i++) {
            String phoneNo = recipients.getString(i);
            try {
                SmsManager smsManager = SmsManager.getDefault();
                if (msg.length() > 160) {
                    ArrayList<String> parts = smsManager.divideMessage(msg);

                    ArrayList<PendingIntent> sentPIarr = new ArrayList<PendingIntent>();
                    ArrayList<PendingIntent> deliveredPIarr = new ArrayList<PendingIntent>();

                    for (int m = 0; m < parts.size(); m++) {
                        sentPIarr.add(PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0));
                        deliveredPIarr.add(PendingIntent.getBroadcast(this, 0,new Intent(DELIVERED), 0));
                    }

                    smsManager.sendMultipartTextMessage(phoneNo, null, parts, sentPIarr, deliveredPIarr);
                } else {
                    smsManager.sendTextMessage(phoneNo, null, msg, null, null);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                sendCallback(false, false, true);
                return;
            }
        }

        sendCallback(true, false, false);

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小伙你站住 2025-02-16 21:29:48

这对我有用

private void sendDirect(ReadableMap options, Callback callback) {

        String msg = options.hasKey("body") ? options.getString("body") : "";
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        ReadableArray recipients = options.hasKey("recipients") ? options.getArray("recipients") : null;
        for (int i = 0; i < recipients.size(); i++) {
            String phoneNo = recipients.getString(i);
            try {
                SmsManager smsManager = SmsManager.getDefault();
                if (msg.length() > 160) {
                    ArrayList<String> parts = smsManager.divideMessage(msg);

                    smsManager.sendMultipartTextMessage(phoneNo, null, parts, null, null);
                } else {
                    smsManager.sendTextMessage(phoneNo, null, msg, null, null);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                sendCallback(false, false, true);
                return;
            }
        }

        sendCallback(true, false, false);

    }
}

This worked for me

private void sendDirect(ReadableMap options, Callback callback) {

        String msg = options.hasKey("body") ? options.getString("body") : "";
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        ReadableArray recipients = options.hasKey("recipients") ? options.getArray("recipients") : null;
        for (int i = 0; i < recipients.size(); i++) {
            String phoneNo = recipients.getString(i);
            try {
                SmsManager smsManager = SmsManager.getDefault();
                if (msg.length() > 160) {
                    ArrayList<String> parts = smsManager.divideMessage(msg);

                    smsManager.sendMultipartTextMessage(phoneNo, null, parts, null, null);
                } else {
                    smsManager.sendTextMessage(phoneNo, null, msg, null, null);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                sendCallback(false, false, true);
                return;
            }
        }

        sendCallback(true, false, false);

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文