본문 바로가기
Program

phonegap-android-eclipse-quickstart

본문

http://wiki.phonegap.com/w/page/30862722/phonegap-android-eclipse-quickstart

This is a tutorial for working with PhoneGap for Android on Eclipse with the .

 

Requirements

 

It is assumed that you have the Android SDK installed and working. If not, then you need to install it before proceeding. You can find the download and installation instructions . Also, ensure that you have created at least one Android virtual device (AVD). You will need an AVD to run your project in the Android emulator.

 

You also need to:

 and extract its contents. We are only interested in the Android directory. 

 

In Eclipse, ensure that you have told Eclipse where the Android SDK is installed in Preferences > Android. (See below.)

 

 

Now you can either build the sample project or skip down to create a new project.

 

Building The Sample Project

 

File > New > Android Project

 

Select Create new project from existing source Click Browse and point it to the location of the sample app provided with your PhoneGap 0.9.4 download

Don't bother using older versions of Android. Use the highest SDK target available. Phonegap will take care of backwards compatibility for you.  Note: You may experience issues with Android 3.0 so try using Android 2.2 or 2.3 first.

 

(You might experience an error here, where Eclipse can't find phonegap.jar. In this case, right click on the /libs folder and go to Build Paths/ > Configure Build Paths. Then, in the Libraries tab, add phonegap.jar to the Project. If Eclipse is being temperamental, you might need to refresh (F5) the project.)

 

You can now run you project as an Android Application. Right click the project and go to Run As and click Android Application.  Eclipse might ask you to select an appropriate AVD. If there isn't one, then you'll need to create it before you can continue.

 

 

 

Creating A New Project

 

File > New > Android Project

 

 

And give it some sensible defaults. 

 

 

Don't bother using older versions of Android. Use the highest SDK target available. Phonegap will take care of backwards compatibility for you.

 

From the PhoneGap download earlier, we need the following two files:

Android/phonegap-1.0.0.jar Android/phonegap-1.0.0.js

 

In the root directory of the project you created in Eclipse, create two new directories:

/libs /assets /www

 

Now copy

Android/phonegap.0.9.4.jar to /libs  Android/phonegap.0.9.4.js  to /assets/www

 

In Eclipse, select the project in the Package Explorer and refresh (F5) the project. The copied file will appear in the project.

 

Now, create index.html in your www folder and add some code like so:

 

<!DOCTYPE HTML>
<html>

  <head>
    <title>PhoneGap</title>

  <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>      

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

     function onLoad(){

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

     }

     function onDeviceReady(){

          navigator.notification.alert("PhoneGap is working");

     }

  </script>

  </head>

  <body onload="onLoad();">
       <h1>Welcome to PhoneGap</h1>

       <h2>Edit assets/www/index.html</h2>

  </body>

</html>

 

 

Make a few adjustments to the project's main Java file found in the src folder in Eclipse.

Change the class's extend from Activity to DroidGap Replace the setContentView() line with super.loadUrl("file:///android_asset/www/index.html"); Add import com.phonegap.*;

 

 

(You might experience an error here, where Eclipse can't find phonegap-1.0.0.jar. In this case, right click on the /libs folder and go to Build Paths/ > Configure Build Paths. Then, in the Libraries tab, add phonegap-1.0.0.jar to the Project. If Eclipse is being temperamental, you might need to refresh (F5) the project once again.)

 

Finally, lets add some permissions to the AndroidManifest.xml file to allow phonegap to run properly.

Open up your manifest file in your favourite editor and paste the following information after the versionName but before the application tag:

 

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

 

 

 

In AndroidManifest.xml, make sure the activity tag contains the following attribute:

 

    android:configChanges="orientation|keyboardHidden"

 

This tells android not to reload index.html when these events happen; phonegap will handle these events appropriately.

 

Last step is to copy the xml folder that came with the PhoneGap download into the res folder of your project.

 

You can now run you project as an Android Application. Right click the project and go to Run As and click Android Application.  Eclipse might ask you to select an appropriate AVD. If there isn't one, then you'll need to create it before you can continue.

 

If all goes well then the AVD will load in the emulator -- be prepared to wait for this -- and you application will be uploaded, installed, and run.

 

 

Have fun!

[이 게시물은 듀라님에 의해 2015-04-03 10:08:13 워드프레스에서 이동 됨]
[이 게시물은 듀라님에 의해 2015-04-03 10:27:24 Public에서 이동 됨]
[이 게시물은 듀라님에 의해 2015-04-03 10:33:53 팁과강좌에서 이동 됨]
[이 게시물은 최고관리자님에 의해 2017-06-10 14:26:27 Mobile에서 이동 됨]
0 0
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기
  • 카카오톡으로 보내기

페이지 정보

l2j (121.♡.101.20) 작성일11-09-03 20:21 조회1,479회 댓글0건

댓글목록

등록된 댓글이 없습니다.

Program 목록

게시물 검색

사이트 정보

  • 회사명 회사명 / 대표 대표자명
  • 주소 OO도 OO시 OO구 OO동 123-45
  • 사업자 등록번호 123-45-67890
  • 전화 02-123-4567 / 팩스 02-123-4568
  • 통신판매업신고번호 제 OO구 - 123호
  • 개인정보관리책임자 정보책임자명

고객센터

  • 02-1234-5678
  • abc@abc.com
  • 월-금 am 11:00 - pm 05:00
  • 점심시간 : am 12:00 - pm 01:00
  • 주말&공휴일은 1:1문의하기를 이용하세요.
상단으로