Andriod phoneGap 入门

1.下载phoneGap(我之前用还是cordova-1.5.0.jar)

http://phonegap.com/download/#autodownload

解压出来,找到lib/android目录。

2.在assets目录下新建文件夹“www”

Andriod phoneGap 入门

3.在www目录下新建一个html文件index.html。我们的界面就要在这里建立了。

4.把lib/android目录下的xml文件夹整个复制到res面目下

Andriod phoneGap 入门

5.修改AndroidManifest.xml添加用户权限

     <supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

6.修改MainAcivity.java

 public class DemoActivity extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty( "splashscreen", R.drawable.splash); //html文件加载慢,设置超时时间
super.setIntegerProperty("loadUrlTimeoutValue", 120000);
super.loadUrl("file:///android_asset/www/index.html");
}
}

8.e.g.

1)声明一个a标签:

 <a href="#" data-icon="check" id="photo">拍照</a>

2)初始化a标签的tap事件:

 $("#photo").live("tap",getPhoto);

3)tap事件:

 function getPhoto(){
if(!navigator.camera) {
alert("camera can not use");
return;
}
navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); function onSuccess(imageData) {
//alert("camer successful!!!");
//alert(imageData);
var newnote=$("#newNote");
var src=imageData;
//var src="data:image/jpeg;base64," + imageData;
var img=$("#myPhoto");
img.attr("src", src);
img.css("display", "block");
//var img="<img src="+src+"/>";
//newnote.append(img);
newnote.listview("refresh");
} function onFail(message) {
alert(' carema Failed because: ' + message);
} }
上一篇:JavaWeb核心编程之(三.4)Servlet Context 配置


下一篇:mysql5.7 二进制包安装