1.下载phoneGap(我之前用还是cordova-1.5.0.jar)
http://phonegap.com/download/#autodownload
解压出来,找到lib/android目录。
2.在assets目录下新建文件夹“www”
3.在www目录下新建一个html文件index.html。我们的界面就要在这里建立了。
4.把lib/android目录下的xml文件夹整个复制到res面目下
5.修改AndroidManifest.xml添加用户权限
1 <supports-screens 2 android:largeScreens="true" 3 android:normalScreens="true" 4 android:smallScreens="true" 5 android:resizeable="true" 6 android:anyDensity="true" 7 /> 8 <uses-permission android:name="android.permission.CAMERA" /> 9 <uses-permission android:name="android.permission.VIBRATE" /> 10 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 11 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 12 <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 13 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 14 <uses-permission android:name="android.permission.INTERNET" /> 15 <uses-permission android:name="android.permission.RECEIVE_SMS" /> 16 <uses-permission android:name="android.permission.RECORD_AUDIO" /> 17 <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 18 <uses-permission android:name="android.permission.READ_CONTACTS" /> 19 <uses-permission android:name="android.permission.WRITE_CONTACTS" /> 20 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 21 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 23 <uses-permission android:name="android.permission.FLASHLIGHT"/> 24 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
6.修改MainAcivity.java
1 public class DemoActivity extends DroidGap { 2 /** Called when the activity is first created. */ 3 @Override 4 public void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 super.setIntegerProperty( "splashscreen", R.drawable.splash); 8 //html文件加载慢,设置超时时间 9 super.setIntegerProperty("loadUrlTimeoutValue", 120000); 10 super.loadUrl("file:///android_asset/www/index.html"); 11 } 12 }
8.e.g.
1)声明一个a标签:
1 <a href="#" data-icon="check" id="photo">拍照</a>
2)初始化a标签的tap事件:
1 $("#photo").live("tap",getPhoto);
3)tap事件:
1 function getPhoto(){ 3 if(!navigator.camera) { 4 alert("camera can not use"); 5 return; 6 } 7 navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); 8 9 function onSuccess(imageData) { 10 //alert("camer successful!!!"); 11 //alert(imageData); 12 var newnote=$("#newNote"); 13 var src=imageData; 14 //var src="data:image/jpeg;base64," + imageData; 15 var img=$("#myPhoto"); 16 img.attr("src", src); 17 img.css("display", "block"); 18 //var img="<img src="+src+"/>"; 19 //newnote.append(img); 20 newnote.listview("refresh"); 22 } 23 24 function onFail(message) { 25 alert(‘ carema Failed because: ‘ + message); 26 } 27 29 }
时间: 2024-10-04 08:45:08