Reputation: 3374
I am using Phonegap to create plugin aimed at sending SMS. Below is the function I use to do it.
private void sendSMS(String phoneNumber, String message) {
// Activity currentActivity = (Activity)this.ctx;
SmsManager manager = SmsManager.getDefault();
PendingIntent sentIntent = PendingIntent.getActivity(cordova.getContext(), 0, new Intent(), 0);
manager.sendTextMessage(phoneNumber, null, message, sentIntent, null);
}
When the variable "message" contains English, everything works fine. But if the message is in Hebrew, I receive an error.
See below input in Hebrew
סך הלכל מוזמן 2 פריטים סלט פיצוצ בסרי שווה ל 10.3 כמות 1 סלט שרימפס שווה ל 8.15 כמות 2 סך הכל חשבון 26.6 שקלים
Below is a class that holds the text description. I suspect that the problem is problem with the unicode, but I do not know how to fix it.
Please help.
public class MenuEntry {
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public MenuEntry() {
super();
this.pid = "";
}
public String GetPriceAndDescription(int unit) {
StringBuilder result = new StringBuilder();
result.append(this.getTitle());
result.append(" שווה ל ");
result.append(this.getPrice());
result.append(" כמות ");
result.append(unit);
result.append("\n");
return result.toString();
}
public String GetPriceAndDescription() {
StringBuilder result = new StringBuilder();
result.append(this.getTitle());
result.append(" שווה ל ");
result.append(this.getPrice());
result.append("\n");
return result.toString();
}
public MenuEntry(String pid, String title, String description, double price, String categoryName) {
super();
this.pid = pid;
this.title = title;
this.description = description;
this.price = price;
this.categoryName = categoryName;
}
private String pid;
private String title;
private String description;
private double price;
private String categoryName;
}
See below the definition of the manifest file, to see the target version.
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
Upvotes: 5
Views: 491
Reputation: 3374
I found the answer. The problem was with the "SmsManager" class. When the message is too long , the class throws exception, but without description.
So I needed to use other method "sendMultipartTextMessage" of the SmsManager class.
private void sendSMS(String phoneNumber, String message) {
SmsManager manager = SmsManager.getDefault();
ArrayList<String> parts = manager.divideMessage(message);
manager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
}
Upvotes: 1