如何在Java中sendmultiparttextmessage
我正在尝试修改现有插件以启用其发送长短信。我对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用
This worked for me