5

我正在使用 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);
}

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

请参阅以下希伯来语输入

סךהלכלמןמן2简约סלטיצוצצוציצוצצוצפלללללל.ותותלללללללללפסיפסייייייפספספספספספספספספסלללללללללללללללללללללללל

下面是一个包含文本描述的类。我怀疑问题出在 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" />
4

1 回答 1

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

}
于 2012-11-25T19:49:35.977 回答