PhoneGap gives you the power to write your App in JavaScript language and build it for native platforms like Android/iOS/Windows/BlackBerry etc. This saves a lot of time and effort for an App Developer as he won’t have to write UI and Business Logic for porting it to different platforms. If your HTML 5 App is build using App42 Backend, you can also build your App for different platforms like Android and iOS using PhoneGap. App42 JavaScript APIs are compatible to work with PhoneGap.
Below is the step by step guide to build App42 “To-Do” Sample Application for Android device using PhoneGap.
Download and Initialize App42 Java Script To-Do List Sample:
1. Register with App42 platform.
2. Go to dashboard and click on the Create App button.
3. Fill all the mandatory fields and and check the ACL = true to get your APIKey and SecretKey.
4. Download App42 Java Script sample app and unzip it on your machine .
5. Edit index.html file and put your APIKey and SecretKey (which were received in step#2 & #3) as shown below:
App42.initialize("Your APIKey","Your SecretKey");
Prepare Android Setup
- Download and Install Android SDK. For details please see http://developer.android.com/sdk/index.html
- Download PhoneGap Binaries from https://github.com/phonegap/phonegap/archive/2.9.0.zip
Build Sample for Android:
- Create new android project (Android 2.3.3) in eclipse.
- Create folder www in assets and add App42 To-Do Sample (Content of Root Folder) into it.
- Now add jar file cordova-2.9.0.jar to libs folder (It is available in PhoneGap binary distribution downloaded in above step)
- Also add cordova-2.9.0.js(Available inside PhoneGap disribution) in www folder.
- Import cordova-2.9.0.js into your project i.e in index.html as shown below
script type="text/javascript" src="cordova-2.9.0.js"
Open MainActivity.java file and add an import statement for org.apache.cordova.DroidGap and extend it with the same.
import org.apache.cordova.DroidGap;
public class MainActivity extends DroidGap
- Modify onCreate method to load index.html as shown below.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
- Open the AndroidManifest.xml and add a child element to the application node as shown below
- Add child uses-permission node to the manifest node as shown below
- To run your android application right click on your project and run as Android Application.
- This will create apk file that you can run in emulator or device.
Leave A Reply