PhoneGap +Android start 的一天
发布于 13 年前 作者 acter 5712 次浏览 最后一次编辑是 8 年前

先工具准备: <br/> <br/>1:Eclipse  下载地址:http://www.eclipse.org/downloads/ <br/> <br/>2:Android SDK <a href=“http://developer.android.com/sdk/index.html”>Android SDK</a>   http://developer.android.com/sdk/index.html <br/> <br/>3:<a href=“http://developer.android.com/sdk/eclipse-adt.html#installing”>ADT Plugin http://developer.android.com/sdk/eclipse-adt.html#installing</a> <br/> <br/>4:PhoneGap  http://www.phonegap.com/ <br/><h3>配置新的项目</h3> <br/>打开 Eclipse,在文件菜单下面点击 <strong>New > Android Project</strong> <br/><ul> <br/> <li>在项目的根目录, 创建两个目录: <br/><ul> <br/> <li>/libs</li> <br/> <li>/assets/www</li> <br/></ul> <br/></li> <br/> <li>从刚才下载的PhoneGap中复制phonegap.js 到/assets/www目录</li> <br/> <li>从刚才下载的PhoneGap中复制phonegap.jar 到/libs目录</li> <br/> <li>从刚才下载的PhoneGap中复制xml文到夹到/res 目录</li> <br/> <li>M对Eclipse的src文件夹中的主Java文件进行少量调整:(如下图) <br/><ul> <br/> <li>将class的继承类由 <strong>Activity</strong>改为<strong>DroidGap</strong></li> <br/> <li>将<strong>setContentView()</strong> 这一行替换为 <strong>super.loadUrl(“file:///android_asset/www/index.html”);</strong></li> <br/> <li>添加<strong>import com.phonegap.*;</strong></li> <br/> <li>移除 <strong>import android.app.Activity;</strong></li> <br/></ul> <br/>2:右键单击AndroidManifest.xml并选择Open With > XMlEditor。加入一下</li> <br/></ul> <br/><pre><supports-screens <br/>android:largeScreens=“true” <br/>android:normalScreens=“true” <br/>android:smallScreens=“true” <br/>android:resizeable=“true” <br/>android:anyDensity=“true” <br/>/> <br/><uses-permission android:name=“android.permission.CAMERA” /> <br/><uses-permission android:name=“android.permission.VIBRATE” /> <br/><uses-permission android:name=“android.permission.ACCESS_COARSE_LOCATION” /> <br/><uses-permission android:name=“android.permission.ACCESS_FINE_LOCATION” /> <br/><uses-permission android:name=“android.permission.ACCESS_LOCATION_EXTRA_COMMANDS” /> <br/><uses-permission android:name=“android.permission.READ_PHONE_STATE” /> <br/><uses-permission android:name=“android.permission.INTERNET” /> <br/><uses-permission android:name=“android.permission.RECEIVE_SMS” /> <br/><uses-permission android:name=“android.permission.RECORD_AUDIO” /> <br/><uses-permission android:name=“android.permission.MODIFY_AUDIO_SETTINGS” /> <br/><uses-permission android:name=“android.permission.READ_CONTACTS” /> <br/><uses-permission android:name=“android.permission.WRITE_CONTACTS” /> <br/><uses-permission android:name=“android.permission.WRITE_EXTERNAL_STORAGE” /> <br/><uses-permission android:name=“android.permission.ACCESS_NETWORK_STATE” /> <uses-permission android:name=“android.permission.GET_ACCOUNTS” /> <br/>完整代码是:</pre> <br/><pre><?xml version=“1.0” encoding=“utf-8”?> <br/><manifest xmlns:android=“http://schemas.android.com/apk/res/android” <br/> package=“com.phonegap.helloworld” <br/> android:versionCode=“1” <br/> android:versionName=“1.0” > <br/> <supports-screens <br/> android:largeScreens=“true” <br/> android:normalScreens=“true” <br/> android:smallScreens=“true” <br/> android:resizeable=“true” <br/> android:anyDensity=“true” <br/> /> <br/> <uses-permission android:name=“android.permission.CAMERA” /> <br/> <uses-permission android:name=“android.permission.VIBRATE” /> <br/> <uses-permission android:name=“android.permission.ACCESS_COARSE_LOCATION” /> <br/> <uses-permission android:name=“android.permission.ACCESS_FINE_LOCATION” /> <br/> <uses-permission android:name=“android.permission.ACCESS_LOCATION_EXTRA_COMMANDS” /> <br/> <uses-permission android:name=“android.permission.INTERNET” /> <br/> <uses-permission android:name=“android.permission.RECEIVE_SMS” /> <br/> <uses-permission android:name=“android.permission.RECORD_AUDIO” /> <br/> <uses-permission android:name=“android.permission.RECORD_VIDEO”/> <br/> <uses-permission android:name=“android.permission.MODIFY_AUDIO_SETTINGS” /> <br/> <uses-permission android:name=“android.permission.READ_CONTACTS” /> <br/> <uses-permission android:name=“android.permission.WRITE_CONTACTS” />
<br/> <uses-permission android:name=“android.permission.WRITE_EXTERNAL_STORAGE” />
<br/> <uses-permission android:name=“android.permission.ACCESS_NETWORK_STATE” /> <br/> <uses-permission android:name=“android.permission.GET_ACCOUNTS” /> <br/> <uses-permission android:name=“android.permission.BROADCAST_STICKY” /> <br/>
<br/> <uses-feature android:name=“android.hardware.camera” /> <br/> <uses-feature android:name=“android.hardware.camera.autofocus” /> <br/>
<br/> <uses-sdk android:minSdkVersion=“8” /> <br/> <br/> <br/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" <br/> android:debuggable=“true”> <br/> <activity android:name=".App" android:label="@string/app_name" <br/> android:configChanges=“orientation|keyboardHidden”> <br/> <intent-filter> <br/> <action android:name=“android.intent.action.MAIN” /> <br/> <category android:name=“android.intent.category.LAUNCHER” /> <br/> </intent-filter> <br/> </activity> <br/> <activity android:name=“com.phonegap.DroidGap” android:label="@string/app_name" <br/> android:configChanges=“orientation|keyboardHidden”> <br/> <intent-filter> <br/> </intent-filter> <br/> </activity> <br/> </application> <br/></manifest> <br/>之后 就是index.html <br/> <br/>随便写点就行了。 <br/> <br/></pre> <br/><ul> <br/> <li> <br/><h3>5A. 部署到模拟器</h3> <br/><ul> <br/> <li>右键单击项目节点选择<strong>Run As</strong> 然后点击 <strong>Android Application</strong></li> <br/> <li>Eclipse将要求你选择一个合适的AVD,如果没有设置的话,你需要创建一个AVD。</li> <br/></ul> <br/></li> <br/> <li> <br/><h3>5B. 部署到设备</h3> <br/><ul> <br/> <li>确认设备已经勾选USB debugging选项,并已将设备连接到电脑。(设置 > 应用程序 > 开发)</li> <br/> <li>右键单击项目节点选择 <strong>Run As</strong>然后点击<strong>Android Application</strong></li> <br/></ul> <br/>爱看英文的去看英文教程:http://www.phonegap.com/start#android</li> <br/> <li>爱看图解释的 去看:http://phonegapcn.com/developers/get-started</li> <br/></ul> <br/><pre> <br/>到此为止,我手机有自己编写的HelloWorld 了 <br/>我遇到的问题是 我少了一步 总是进程stop 那就是 xml 没复制进去 <br/> <br/> <br/></pre>

回到顶部