blackberry widget开发技术提高(五)

来源:互联网 发布:奶奶杀死孙女知乎 编辑:程序博客网 时间:2024/05/16 12:57

步骤十四

所有的这些设置做完之后,剩下来的就是要测试运行了,如开发入门中的方式我们可以添加一个新的widget。在你的计算机上创建一个c:/widget/alert目录(也可以工作在别的目录),在这个目录中生成两个index.html config.xml文件,正如基础篇介绍的那样。

定义的index.htmlconfig.xml如下所示:

<html>

<head>

<meta name="viewport" content="width=device-width; height=device-height" />

<script type="text/JavaScript">

function vibrateAlert() {

if (sample.alert.vibrateSupported)

{

    sample.alert.vibrate(1000);

}

else

    alert('extension not supported');

}

</script>

</head>

<body>

<div>

<input type="submit" value="Alert" onclick="vibrateAlert()" />

</div>

</body>

</html>

 

 

Config.xml的内容如下:

<?xml version="1.0" encoding="utf-8" ?>

<widget xmlns="http://www.w3.org/ns/widgets"

        xmlns:rim="http://www.blackberry.com/ns/widgets"

        version="1.0.0">

 

            <name> Alert Widget </name>

            <description>

                        Sample widget that demonstrates how to use

                        the Alert API to vibrate the BlackBerry Smartphone

            </description>

 

            <author href="http://www.rim.com/"

                                    rim:copyright="no copyright"     

                                    email="author_name@authordomain.com">

                        Company Name ? Author Name

            </author>

 

            <content src="index.html" />

            <feature id="sample" />

 

</widget>

 

在入门文档中,我们是通过eclipse自动打包这两个文件成cod的,这里我们也可以使用另外一种手工通过bbwp打包工具完成这一步,先zip然后生成cod

首先把这两个文件压缩为一个zip包,名为alert.zip

然后执行如下命令

 

这里的bbwp.exe位于安装好的widget sdk的目录下面。在执行完上述命令后在命令行出可以看到如下输出,最后在zip同级目录下会生成一个bin目录,如果基础篇介绍的,bin目录下,我们可以发现最后生成的cod文件。

验证

完成这一步,就可以把模拟器自动启动了.最后在模拟器中或者真机上, 就可以看到我们的widget的效果,如果上一篇基础篇的介绍那样,到这里,一个基于我们新的扩充的widget的开发API的新的widget的开发就完成了。点击Alert 按钮,就可以体验我们新添加的API能提供的功能了。

 

 

 

原创粉丝点击