【发布时间】:2016-02-16 08:07:39
【问题描述】:
作为注册的一部分,我正在尝试将所有电话联系人添加到我的应用程序中,并且我希望为联系人加载图像(不可协商)。
我使用下面的代码使应用程序在 iOS 上崩溃并且在 Android 上非常慢。在Codename one 中加载所有电话联系人的最佳方式是什么?
其他应用程序可以在很短的时间内获取我的所有联系人,所以我确信这可以做到。为什么代码会在 iOS 上让我的应用崩溃?
Image defaultIcon = fontIcon("\ue113", 7, 0xbcbcbc);
try {
InfiniteProgress progress = new InfiniteProgress();
progress.setAnimation(fontIcon(FontIcon.FONTICON_SPIN6 + "", 4, 0x12a4f4));
Dialog ipDlg = progress.showInifiniteBlocking();
final String[] myContacts = Display.getInstance().getAllContacts(true);
for (final String contactId : myContacts) {
Contact contact = Display.getInstance().getContactById(contactId, true, true, true, true, true);
Hashtable numbers = contact.getPhoneNumbers();
Enumeration nums = numbers.elements();
String firstName = contact.getFirstName() != null ? contact.getFirstName() : "";
String familyName = contact.getFamilyName() != null ? contact.getFamilyName() : "";
String names = firstName + " " + familyName;
while (nums.hasMoreElements()) {
String phoneNumber = (String) nums.nextElement();
MultiButton multiContact = new MultiButton(names);
multiContact.setTextLine2(phoneNumber);
Image img = contact.getPhoto();
multiContact.setIcon(img != null ? img.scaledWidth(Size(7)) : defaultIcon);
content.add(multiContact);
}
}
ipDlg.dispose();
} catch (Exception ex) {
}
【问题讨论】:
标签: java codenameone