黑莓 - 让来自本地地址簿通话 [英] Blackberry - make a call from native address book
问题描述
如何从菜单项中BB的本土书附加呼叫(选项'从ABC呼叫')?
how to make a call from menu item appended in native book of BB('Call from ABC' option)?
推荐答案
有关RIM OS 4.7和较少使用的调用:
Initiate call programmatically
For RIM OS 4.7 and lower use Invoke:
PhoneArguments phoneArgs = new PhoneArguments(PhoneArguments.ARG_CALL,
"555-5555");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, phoneArgs);
有关RIM OS 5.0宣布我们可以使用<一个href=\"http://www.blackberry.com/developers/docs/5.0.0api/net/rim/blackberry/api/phone/Phone.html#initiateCall%28int,%20java.lang.String%29\"相对=nofollow> Phone.initiateCall 方式:
For RIM OS 5.0 declared we can use Phone.initiateCall method:
Phone.initiateCall(Phone.getLineIds()[0], "519-555-0100");
请参阅从BlackBerry设备拨打电话应用程序(多线路环境)
要添加呼叫通过ABC项通讯录菜单,我们需要做以下几点:
To add your "Call via ABC" item to address book menu we need to do following:
- 实现自定义的项目作为扩展<一个href=\"http://www.blackberry.com/developers/docs/4.1api/net/rim/blackberry/api/menuitem/ApplicationMenuItem.html\"相对=nofollow> ApplicationMenuItem
- 使用添加自定义项的实例菜单<一个href=\"http://www.blackberry.com/developers/docs/4.5.0api/net/rim/blackberry/api/menuitem/ApplicationMenuItemRepository.html\"相对=nofollow> ApplicationMenuItemRepository
- 部署到实际设备之前,别忘了迹象您code (最多可能需要2周)
- implement custom item as an extension to ApplicationMenuItem
- add instance of custom item to menu using ApplicationMenuItemRepository
- before deploying to the real device, don't forget to sign your code (may take up to 2 weeks)
现在,实现自定义的菜单项:
Now, implementing custom menu item:
class AdressBookMenuItem extends ApplicationMenuItem {
Contact mContact;
public AdressBookMenuItem(int order) {
super(order);
}
public Object run(Object context) {
if (context instanceof Contact) {
mContact = (Contact) context;
if (0 < mContact.countValues(Contact.TEL)) {
String phone = mContact.getString(Contact.TEL, 0);
PhoneArguments args = new PhoneArguments(
PhoneArguments.ARG_CALL, phone);
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
} else {
Dialog.alert("This contact has no phone number");
}
}
return null;
}
public String toString() {
return "Call via ABC";
}
}
现在把它添加到地址簿:
Now add it to the address book:
AdressBookMenuItem menuItem = new AdressBookMenuItem(0);
ApplicationMenuItemRepository repository =
ApplicationMenuItemRepository.getInstance();
long id = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
repository.addMenuItem(id, menuItem);
把所有一起
- 运行应用程序
- preSS呼叫按钮
- 选择联系人
- 开启菜单
您应该看到
在测试了9000大胆
全code:
Tested on Bold 9000 simulator
Full code:
import javax.microedition.pim.Contact;
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.PhoneArguments;
import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class CallIntegrate extends UiApplication {
public CallIntegrate() {
pushScreen(new Scr());
}
public static void main(String[] args) {
CallIntegrate app = new CallIntegrate();
app.enterEventDispatcher();
}
}
class AdressBookMenuItem extends ApplicationMenuItem {
Contact mContact;
public AdressBookMenuItem(int order) {
super(order);
}
public AdressBookMenuItem(Object context, int order) {
super(context, order);
}
public Object run(Object context) {
if (context instanceof Contact) {
mContact = (Contact) context;
if (0 < mContact.countValues(Contact.TEL)) {
String phone = mContact.getString(Contact.TEL, 0);
PhoneArguments args = new PhoneArguments(
PhoneArguments.ARG_CALL, phone);
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
} else {
Dialog.alert("This contact has no phone number");
}
}
return null;
}
public Contact getContact() {
return mContact;
}
public String toString() {
return "Call via ABC";
}
}
class Scr extends MainScreen {
public Scr() {
super(DEFAULT_MENU|DEFAULT_CLOSE);
String label = "Now please go to blackberry adressbook, "
+ "select contact and open menu";
add(new LabelField(label));
AdressBookMenuItem menuItem = new AdressBookMenuItem(0);
ApplicationMenuItemRepository repository =
ApplicationMenuItemRepository.getInstance();
long id = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
repository.addMenuItem(id, menuItem);
}
}
这篇关于黑莓 - 让来自本地地址簿通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!