1. First: Before installing the PHONEGAP development environment, you need to install the following framework
1.Java SDK (direct download installation)2.Eclipse (recommended classic version)3.Android SDK4.ADT Plugin (SDK and Gap installation complete restart Eclipse)5.PhoneGap (Download complete direct decompression)2. Create a PhoneGap project1. Create a new Android project (name Random);
2. Under your new directory, create a new two subdirectory/libs and/assets/www3. Enter the Anroid directory in the PhoneGap package that you just downloaded and unzipped, and the resources we need are in this directory. Copy the Phonegap-x.x.x.js js file (depending on the version that was downloaded) to the/assets/www directory,Copy the Phonegap.jar file to the/libs directory. copy the XML directory to the Res directory of the Android project. 4. Create a index.html file under/assets/www that looks something like this:
<!DOCTYPE HTML> <HTML> <Head> <title>PhoneGap</title> <Scripttype= "Text/javascript"CharSet= "Utf-8"src= "Phonegap-x.x.x.js"></Script> </Head> <Body> <H1>Hello World</H1> </Body></HTML>
5. Copy the XML contents of the following permissions configuration into the Androidmanifest.xml file:
<Supports-screensAndroid:largescreens= "true"Android:normalscreens= "true"Android:smallscreens= "true"android:resizeable= "true"android:anydensity= "true"/><uses-permissionAndroid:name= "Android.permission.CAMERA" /><uses-permissionAndroid:name= "Android.permission.VIBRATE" /><uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION" /><uses-permissionAndroid:name= "Android.permission.ACCESS_FINE_LOCATION" /><uses-permissionAndroid:name= "Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /><uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE" /><uses-permissionAndroid:name= "Android.permission.INTERNET" /><uses-permissionAndroid:name= "Android.permission.RECEIVE_SMS" /><uses-permissionAndroid:name= "Android.permission.RECORD_AUDIO" /><uses-permissionAndroid:name= "Android.permission.MODIFY_AUDIO_SETTINGS" /><uses-permissionAndroid:name= "Android.permission.READ_CONTACTS" /><uses-permissionAndroid:name= "Android.permission.WRITE_CONTACTS" /><uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE" /> <uses-permissionAndroid:name= "Android.permission.GET_ACCOUNTS" />
6. Add the following to the Activity tab of the Androidmanifest.xml file:
Android:configchanges= "Orientation|keyboardhidden
7.androidmanifest.xml finally looks like this: 8. Locate the Libs directory in the newly created Android project and right-click on the Phonegap-x.x.x.jar to select Build Path->add to B Uild Path 9. Finally, modify the Java Master file under src:1 Add import com.phonegap.*;2 Change the class to inherit as Droidgap;3 by deleting import android.app.Activity;4 Replace the Setcontentview () line with the Super.loadurl ("file:///android_asset/www/index.html");5 In the end it looks like this: You can try to run it, and success will come with Hello World's interface. 3.
PhoneGap Plugin PhoneGap plug-in mechanism is actually an Android class exported as a jar file, and then PhoneGap Project reference, and then through the JS to tune the API:1. Create an android Project; 2. Open the Java Master file and change the inherited class to plugin; 3. Introduce the following classes:
Import Com.phonegap.api.Plugin; Import Com.phonegap.api.PluginResult; Import Com.phonegap.api.PluginResult.Status;
4. Override the Execute method of the parent class:
Public Pluginresult Execute (string action, Jsonarray data, string callbackid) { pluginresult pr=null; if (Action.equals ("Method1")) { pr=new pluginresult (status.io_exception, "method1"); } else if (action.equals ("Method2")) { pr=new pluginresult (Status.ok, "method2"); } return PR; }
Where the first parameter action can be used as the type of classification invocation, we can use this parameter to implement the multi-method function.
The returned Pluginresult instance can describe the execution state of the current result through control of the state status type.
Finally, the code might look like this:
5. Export this class as a JAR (right-->export->jar file on class files)
6. Go back to the PHONEGAP project you created earlier and add the jar to the project by adding it as a method above.
7. Add the following in the/res/xml/plugins.xml file:
<name= "Plugintest" value= "Aralork.moblie.plugin.PluginTest" />name is the class name to use when you call, and value is the full path of the class in the jar package
8. Finally open the assets/www/index.html file and write something similar to this:
<Scripttype= "Text/javascript"CharSet= "Utf-8"src= "Phonegap-x.x.x.js"></Script> <Scripttype= "Text/javascript">phonegap.exec (Successcallback,//the callback method after successFailurecallback,//callback method after failure 'plugintest',//the class name that you just configured 'method1', //the method name, which is the action parameter mentioned earlier ["/sdcard"]); //sdcard Path functionSuccesscallback (data) {alert ("Data:"+data); } functionFailurecallback (data) {alert ("Error:"+data); } </Script>
PHONEGAP Development Environment Construction (record, only for Android)