BlackBerry上不同的消息提醒方法

上传人:宝路 文档编号:22268010 上传时间:2017-11-26 格式:DOC 页数:7 大小:41.03KB
返回 下载 相关 举报
BlackBerry上不同的消息提醒方法_第1页
第1页 / 共7页
BlackBerry上不同的消息提醒方法_第2页
第2页 / 共7页
BlackBerry上不同的消息提醒方法_第3页
第3页 / 共7页
BlackBerry上不同的消息提醒方法_第4页
第4页 / 共7页
BlackBerry上不同的消息提醒方法_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《BlackBerry上不同的消息提醒方法》由会员分享,可在线阅读,更多相关《BlackBerry上不同的消息提醒方法(7页珍藏版)》请在金锄头文库上搜索。

1、几种提醒方式2.1 应用程序图标效果:示例代码:1, 更新应用程序图标为已读Bitmap icon=Bitmap.getBitmapResource(icon/read.gif);net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon);2, 更新应用程序图标为未读Bitmap icon=Bitmap.getBitmapResource(icon/read.gif);net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon);2.2 LED 灯效果:示例代码:1,首

2、先需要 import 相应的 API 包:import net.rim.device.api.system.*;或者import net.rim.device.api.system.LED; 2,关闭 LED 灯if(LED.isSupported(LED.LED_TYPE_STATUS) LED.setState(LED.STATE_OFF); 3,打开 LED 灯或者开启 LED 灯闪烁if(LED.isSupported(LED.LED_TYPE_STATUS)/LED.setState(LED.STATE_ON);/or LED.setState(LED.STATE_BLINKING)

3、; LED.setConfiguration(100, 1000, LED.BRIGHTNESS_100); 4,注意捕获抛出的异常如果 setState(int state)的输入参数为不正确的状态时,可能会抛出异常: IllegalArgumentException2.3 震动示例代码:net.rim.device.api.system.Alert.startVibrate(5*1000);2.4 提示音调用系统声音播放的接口,示例如下:/ create an instance of the player from the InputStreamPlayer player = javax.

4、microedition.media.Manager.createPlayer(path, type);player.realize();player.prefetch();VolumeControl volumeControl = (VolumeControl) player.getControl(VolumeControl);volumeControl.setLevel(100);/ start the playerplayer.start();2.5 Indicator如下图所示,BlackBerry 提供 Indicator 的机制,可以在顶部状态栏显示一个小图标,同时还可以在小图标旁

5、边显示一个数字,来标识是否有新消息到来以及新消息的数目。效果:常用的实现步骤:在系统中注册自己的图标。每来一条新的消息,将图标设为显示状态,并且将图标旁边的数字加 1;当每读一条未读消息,将图标设为隐藏,并将图标旁边的数字减 1.示例代码:第一步:创建 ApplicationIndicatorRegistry 和 ApplicationIcon 对象ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();EncodedImage image = EncodedImage.getEncodedIm

6、ageResource( clowds.gif );ApplicationIcon icon = new ApplicationIcon( image );第二步:注册或者获取 ApplicationIndicator 对象/第一次调用时,通过方法 ApplicationIndicator register(ApplicationIcon icon, boolean iconOnly, boolean visible)来注册 Indicator,其中第二个参数控制是否只显示图标而不显示数字ApplicationIndicator indicator = reg.register( icon,

7、false, true);/以后可以通过以下方法来获取已注册的 Indicator 实例。ApplicationIndicator AppIndicator = reg.getApplicationIndicator();第三步:操作 Indicator(显示 /隐藏/ 删除)/设置图标和数值AppIndicator.set( newIcon, newValue );/显示图标ApplicationIndicator.setVisible(true)./隐藏图标ApplicationIndicator.setVisible(false)./从系统中删除图标的注册信息ApplicationInd

8、icatorRegistry.unregister().3. 在系统的 Message Inbox 中加入你的应用程序系统的 Message Inbox 中是所有消息的唯一入口,包括 Email,SMS/MMS,IM 以及第三方应用的消息。BlackBerry 提供一种机制,允许第三方应用将自己的消息写入 Message Inbox,并且定制这些消息的图标,以及菜单项等。同时可以建立自己的应用程序消息目录,将自己的消息存放在这个目录下。效果:常用的实现步骤:分为两个步骤,第一个步骤是将你的图标和你的应用程序关联起来。在系统的 Message Inbox 中注册你自己应用的消息,并且为这些消息对

9、应上你自己定制的图标,同时为这些消息定制菜单项。 (如上图所示)示例代码如下:调用 EncodedImage.getEncodedImageResource,通过一个图片文件名来生成 ApplicationIcon对象. ApplicationIcon newIcon = new ApplicationIcon( EncodedImage.getEncodedImageResource( ml_sample_new.png ) );ApplicationIcon openedIcon = new ApplicationIcon( EncodedImage.getEncodedImageReso

10、urce( ml_sample_opened.png ) );调用 ApplicationMessageFolderRegistry.registerMessageIcon 来将消息状态/图标,和消息关联起来 int MESSAGE_TYPE = 0;reg.registerMessageIcon( MESSAGE_TYPE, STATUS_NEW, newIcon );reg.registerMessageIcon( MESSAGE_TYPE, STATUS_OPENED, openedIcon );通过以上步骤,当 Message Inbox 中的消息为未读状态时,显示的图标为 newIc

11、on;已读状态时,显示的图标为 openedIcon。第二个步骤是在 BlackBerry 中定义一个消息存放的应用消息目录,以及这个目录对应的消息处理函数。进入应用消息目录的方法如下:查看根目录名的方法,选择桌面“消息” ,进去后点菜单键,向下滚动选择“查看文件夹” ,在目录树中就可以看到你设置的目录名了。示例代码如下:创建一个类,来实现接口 ApplicationMessage public class MLSampleMessage implements ApplicationMessage 获取 ApplicationMessageFolderRegistry 的引用Applicati

12、onMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance(); 在 BlackBerry 上注册自己的应用目录,来存放来自你的应用的消息。在下面,注册了两个目录,一个是 Inbox,另一个是 Deleted Messages。ReadableList inboxMessages = messages.getInboxMessages(); ReadableList deletedMessages = messages.getDeletedMessages(); ApplicationMessageFol

13、der inboxFolder = reg.registerFolder( INBOX_FOLDER_ID, Inbox, inboxMessages );ApplicationMessageFolder deletedFolder = reg.registerFolder( DELETED_FOLDER_ID, Deleted Messages, deletedMessages, false ); 为制定的目录追加事件处理函数 deletedFolder.addListener( this , ApplicationMessageFolderListener.MESSAGE_DELETED

14、);创建一个类,来实现接口 ApplicationMessageFolderListener. public class AppFolderListener implements ApplicationMessageFolderListener 下一步,需要调用 actionPerformed() 来处理 Folder 事件, 这个方法定义在接口 ApplicationMessageFolderListener 中. public void actionPerformed( int action, ApplicationMessage messages, ApplicationMessageFolder folder ) / check if action was performed on multiple messagesif( messages.length = 1 ) switch( action ) case ApplicationMessageFolderListener.MESSAGE_DELETED:messageStore.deleteInboxMessage( message );设置根目录名,之前设置的消息目录会列在这个根目录下。 reg.setRootFolderName( OA List );

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号