PhoneGap简单介绍

一:概述

http://www.phonegap.com/

http://digitaldandelion.net/blog/getting_started_with_phonegap/

http://blog.csdn.net/xyz_lmn/article/details/6253650

随着GoogleAndroid手机和苹果的iPhone手机的逐渐普及,越来越多开发者加入到移动应用开发的大军当中。目前移动终端中的冠亚军Android,应用是基于Java语言基础上进行开发的;而苹果公司的iPhone则是基于C语言开发的。如果开发者编写的应用需要同时在不同的移动设备上运行的话,则必须要掌握多种开发语言,这已经成为开发团队的一大难题,在51CTO专访国内著名移动软件尚邮的首席架构师时也提到过跨平台软件开发的困难。而为了进一步简化移动应用的编程,很多公司推出解决方案,Adobe推出的“AIR for Android”,使FlashAndroid开发本地应用成为可能。而Nitobi公司推也出了一套开源的移动应用解决方案PhoneGap

PhoneGap是一款开源的手机应用开发平台,它仅仅只用HTMLJavaScript语言就可以制作出能在多个移动设备上运行的应用。PhoneGap将移动设备本身提供的复杂的API进行了抽象和简化,提供了一系列丰富的API供开发者调用,只要你会HTMLJavascript或者Java语言,就可以利用PhoneGap提供的API去调用各种功能,PhoneGap就能让你可以制作出在各种手机平台上运行的应用,这对移动应用开发者来说无疑是个福音。 目前,PhoneGap已实现对iPhone/ipadAndroidSymbian,Palm、黑莓各版本绝大部分功能的支持,其中官方文档中对其支持见:http://www.phonegap.com/about/features

 

 

 

二:特性

·       支持6种移动设备平台:iOS, Android, BlackBerry, WebOS, Symbian WRT, Windows Mobile(内部测试),以及桌面环境(内部测试)

·          HTML5 + CSS3 + JavaScript  利用标准的Web技术开发应用

·          Phonegap Build: write once, compile on cloud, run anywhere. 提供在线Builder平台:只写一次,云端编译,运行在任何地方

·       目前已经有上千基于Phonegap的应用AppStore

 

 

三:原理

   android:

   利用webView的发布类为JS接口

   

DroipGap.bindBrowser()将类发布成JS接口

 

HTML页面JS处理

 

WebView

 

浏览器

 

四:phonegap使用流程

1. 新建Activity继承自DroipGap

   重载其中的init方法

   public class MainActivity extends DroidGap

{

    @Override

    public void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        super.loadUrl("file:///android_asset/www/index.html");

    }

 

    @Override

    public void init() {

       super.init();

       this.addService("SMSManager","com.phonegap.SMSManager");

    }

   

}

2. 编写自定义的插件继承自Plugin

public class SMSManager extends Plugin

3.phonegap.js中注册plugin

var SMSManager = function(){};

 

SMSManager.prototype.smssend = function(phonenumber, message){

    console.log("navigator.service.sms smssend: ----------------");

    PhoneGap.exec(nullnull"SMSManager""send", [phonenumber, message]);

}

 

PhoneGap.addConstructor(function() {

    if(typeof navigator.service == "undefined") navigator.service = new Object();

    if(typeof navigator.service.sms == "undefined"navigator.service.sms = new SMSManager();

});

 

5.JS中使用

    function sms_send(){

           navigator.service.sms.smssend("13510567813","this is test phonegap----jimmyliu");

    }

   

posted @ 2012-08-12 15:02  欢喜王子  阅读(378)  评论(0编辑  收藏  举报