Tuesday, March 27, 2012

Setup Android phonegap 1.5 project in Eclipse with new cordova files


Adobe has updated phonegap with the new version with some changes but still no update to the documentation has been made. The new phonegap is not having phonegap.jar and phonegap.js file instead it has got the new cordova-1.5.0.jar  and cordova-1.5.0.js files which are used in a little different way. To setup a project with the new phonegap 1.5 in Eclipse just follow the instructions below.


Launch Eclipse, then under the File menu select New > Android Project
In the root directory of the project, create two new directories:
/libs
/assets/www
Copy cordova-1.5.0.js from your PhoneGap download earlier to /assets/www
Copy cordova-1.5.0.jar from your PhoneGap download earlier to /libs
Copy xml folder from your PhoneGap download earlier to /res
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 org.apache.cordova.*;
Remove import android.app.Activity;



 Right click on AndroidManifest.xml and select Open With > Text Editor
Paste the following permissions under versionName: (view image below)

<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" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

Add android:configChanges="orientation|keyboardHidden" to the activity tag in AndroidManifest.
Add a second activity under you appliction tag in AndroidManifest. (view image below)
<activity android:name="org.apache.cordova.DroidGap" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden"> <intent-filter> </intent-filter> </activity>



Now carry on with the usual procedure and you are ready to go, here is the video below which may guide you to the setup procedure.




No comments:

Post a Comment

Thank you for your feedback and keep visiting...!