Android中的希伯来语短信

时间:2012-11-24 15:28:16

标签: java android unicode phonegap-plugins

我正在使用Phonegap创建旨在发送短信的插件。以下是我用来做的功能。

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);
}

当变量“message”包含英语时,一切正常。但如果 消息是希伯来语,我收到错误。

参见以下希伯来语输入

סךהלכלמוזמן2פריטים סלטפיצוצבסרישווהל10.3כמות1 סלטשרימפסשווהל8.15כמות2  סךהכלחשבון26.6שקלים

下面是一个包含文字说明的类。我怀疑问题是unicode的问题,但我不知道如何解决它。

请帮忙。

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;
}

请参阅下面清单文件的定义,以查看目标版本。

 <uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />

1 个答案:

答案 0 :(得分:1)

我找到了答案。 问题出在“SmsManager”类中。当消息太长时, 该类抛出异常,但没有描述。

所以我需要使用SmsManager类的其他方法“sendMultipartTextMessage”。

private void sendSMS(String phoneNumber, String message) {

        SmsManager manager = SmsManager.getDefault();

        ArrayList<String> parts = manager.divideMessage(message);

        manager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);

}