Steps to setup phonegap

Post on 27-Aug-2014

63 views 3 download

description

Install Phone Gap

transcript

Phonegap on Android

1. Android SDK & Eclipse Setup Install the JDK from the below URL :

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-

1880260.html

File Name: jdk-7u51-windows-x64.exe

Down Load Android Eclipse Bundle from the below URL:

https://developer.android.com/sdk/index.html?hl=sk

Extract the downloaded .ZIP file and install the “SDK Manager” which is one of the

executable file in the extracted folder.

In the opened dialogue box select the items as below

2. Project Setup Down Load the phonegap from below URL & Extract the ZIP file:

https://codeload.github.com/phonegap/phonegap/legacy.zip/2.2.0

Open the Eclipse IDE and create a new android application project (File New

other Project) as below,

Import cordova-2.2.0.jar (Find in the extracted Phonegap folder -> android) file into your project as below

Add cordova-2.2.0.js (Find in the extracted Phonegap folder -> android) file into your assets/www folder.

Copy xml folder came with cordova source into res folder

Replace your activity with this. ( Available in the SRC folder)

package com.example.testhello;

import org.apache.cordova.DroidGap;

import android.os.Bundle;

public class MainActivity extends DroidGap {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.setIntegerProperty("loadUrlTimeoutValue", 60000);

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

}

}

Add index.html file into assets/www folder with this content.

<!DOCTYPE html>

<html>

<head>

<title>Contact Example</title>

<script type="text/javascript" charset="utf-8" src="cordova-

2.2.0.js"></script>

<script type="text/javascript" charset="utf-8">

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {

callFetchContacts();

}

function callFetchContacts(){

var options = new ContactFindOptions();

options.multiple=true;

var fields = ["id","name", "displayName",

"organizations","emails","phoneNumbers","addresses"];

navigator.contacts.find(fields, onSuccess, onError, options);

}

function onSuccess(contacts) {

alert('Done');

alert(contacts.length);

for(var i = 0; i < contacts.length; i++){

alert(contacts[i].displayName);

}

};

function onError(contactError) {

alert('onError!');

}

</script>

</head>

<body>

<h1>Example</h1>

<p>Display Contacts</p>

</body>

</html>

Add following permissions into your Manifest file.

<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.INTERNET" />

<uses-permission android:name="android.permission.RECEIVE_SMS" />

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.RECORD_VIDEO"/>

<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.GET_ACCOUNTS" />

<uses-permission android:name="android.permission.BROADCAST_STICKY"

/>