当前位置: 代码迷 >> Android >> phoneGap-Android寮?鍙戠幆澧冩惌寤?杞
  详细解决方案

phoneGap-Android寮?鍙戠幆澧冩惌寤?杞

热度:962   发布时间:2016-04-28 07:17:59.0
phoneGap-Android寮?鍙戠幆澧冩惌寤?杞?
涓?.瀹夎?
鍦ㄥ畨瑁匬honeGap寮?鍙戠幆澧冧箣鍓嶏紝闇?瑕佹寜椤哄簭瀹夎?浠ヤ笅宸ュ叿锛?/div>
1.Java SDK
聽 java sdk锛屼笉瀹夎?鐨勮瘽涓嶈兘姝e父瀹夎?Android SDK銆?/div>
聽 瀹夎?鎴愬姛妫?娴嬶細鍚?姩DOS绐楀彛start-->run-->cmd锛屽湪DOS绐楀彛涓?敭鍏ワ細java -version锛屽?鑳芥樉绀虹増鏈?俊鎭??鏄庡畨瑁呮?甯搞??/div>
2.Eclipse
聽 java寮?鍙戝伐鍏凤紝杩欐垜灏变笉鐢ㄥ?璇翠簡锛屾帹鑽愯?classic鐗堢殑銆?/div>
3.Android SDK
聽 涓嬩笅鏉ュ畨瑁呭畬涔嬪悗鏄?竴涓狝ndroid SDK Manager锛屼綘闇?瑕佷笅杞戒互涓嬬粍浠讹紝鍙?兘闇?瑕佽緝闀挎椂闂达細



4.ADT Plugin
聽 杩欐槸涓?涓狤clipse鎻掍欢锛屼綔鐢ㄦ槸鍏宠仈Android SDK锛屼娇浣犵殑Eclipse鑳藉?鏂板缓Android宸ョ▼锛屽畨瑁呮柟娉曞?涓嬶細
聽 鎵撳紑Eclipse涓?殑鑿滃崟 鈥淗elp鈥?>鈥滻nstallNewSoftware鈥濊繘鍏ヨ蒋浠跺畨瑁呯晫闈?紝鐐瑰嚮鈥淎dd鈥濇寜閽?紝濡備笅鍥捐?缃?嵆鍙?笅杞姐??/div>



5.PhoneGap
聽 涓嬭浇PhoneGap锛岃В鍘嬬缉鍗冲彲锛屾墦寮?閲岄潰鐨刲ibs>android鏂囦欢澶癸細



鍏朵腑鏍囩孩鐨勪笁涓?枃浠跺す鏄?垜浠?渶瑕佺敤鍒扮殑銆?/p>

浜?鏂板缓涓?涓狿honeGap椤圭洰

1.鍦╡clipse涓?柊寤篈ndroid Project銆?/div>
2.鍦ㄩ」鐩?殑鐩?綍涓嬶紝寤轰袱涓?枃浠跺す锛?/div>
/libs
/assets/www
3.杩涘叆灏嗗垰鍒氫笅杞藉苟瑙e帇鐨凱honeGap鍖呴噷Anroid鐩?綍锛屾垜浠?渶瑕佺殑璧勬簮閮藉湪杩欎釜鐩?綍涓嬨??/div>
聽灏哻ordova-2.0.0.js杩欎釜js鏂囦欢(鍏蜂綋鍚嶇О瑙嗗綋鏃朵笅杞界殑鐗堟湰鑰屽畾)copy鍒?assets/www鐩?綍涓?
聽鎶奵ordova-2.0.0.jar鏂囦欢copy鍒?libs鐩?綍涓嬨??/div>
聽鍐嶆妸xml鐩?綍锛坸ml鏁翠釜鏂囦欢澶癸級copy鍒癮ndroid椤圭洰鐨剅es鐩?綍涓嬨??/div>
4.鍦?assets/www涓嬪缓绔媔ndex.html鏂囦欢锛屽唴瀹圭湅璧锋潵鍍忚繖鏍凤細聽
澶嶅埗浠g爜
<!DOCTYPE HTML><html>    <head>        <title>PhoneGap</title>        <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>    </head>    <body>        <h1>Hello World</h1>    </body></html>
澶嶅埗浠g爜

5.灏嗕互涓嬫潈闄愰厤缃?殑xml鍐呭?copy鍒癆ndroidManifest.xml鏂囦欢涓?細

澶嶅埗浠g爜
<supports-screensandroid: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" />
澶嶅埗浠g爜
6.灏嗕互涓嬪唴瀹规坊鍔犲埌AndroidManifest.xml鏂囦欢鐨刟ctivity鏍囩?涓?

android:configChanges="orientation|keyboardHidden

杩欐槸涓轰簡淇濊瘉鏈哄櫒鍦ㄦí绔栧睆鍒囨崲鐨勬椂鍊欎笉浼氶噸鏂版墽琛孉ctivity鐨刼nCreate鏂规硶锛?/p>

7.AndroidManifest.xml鏈?鍚庣湅璧锋潵浼氬儚杩欐牱锛?/p>

澶嶅埗浠g爜
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.shawn"    android:versionCode="1"    android:versionName="1.0">    <supports-screens        android:anyDensity="true"        android:largeScreens="true"        android:normalScreens="true"        android:resizeable="true"        android:smallScreens="true"        android:xlargeScreens="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.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" />    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />    <application android:label="@string/app_name"        android:icon="@drawable/ic_launcher"        android:theme="@style/AppTheme">        <activity            android:name="outer"            android:configChanges="orientation|keyboardHidden"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>
澶嶅埗浠g爜

鍏朵腑<application>鏍囩?鎴戜滑鍙?互鐪嬪仛鏄?垜浠?綋鍓嶇殑搴旂敤锛岃??lt;activity>浠h〃鎴戜滑搴旂敤鍐呯殑涓?涓?晫闈?紝<intent-filter>鏍囩?閲屾垜浠?粰褰撳墠椤甸潰璁剧疆浜嗕竴涓?潈闄?/p>

android.intent.action.MAIN琛ㄧず鏄?渶鍏堝惎鍔ㄧ殑鐨勭晫闈?紱

android.intent.category.LAUNCHER鍐冲畾搴旂敤绋嬪簭鏄?惁鏄剧ず鍦ㄧ▼搴忓垪琛ㄩ噷锛?br>

鍙﹀?闇?瑕佹敞鎰忕殑鏄?細

<activity android:name="outer" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" >

鎴戜滑鐨?lt;activity>鏍囩?涓?湁杩欐牱涓?涓?被鍚峯uter锛屾垜浠?彲浠ヨ嚜宸卞畾涔夊畠锛屼竴浼氬効鎴戜滑浼氱敤鍒拌繖涓?被鍚嶃??/span>

8.鍦ㄥ垰鍒氭柊寤虹殑Android Project涓?壘鍒發ibs鐩?綍骞跺湪cordova-2.0.0.jar涓婄偣鍑诲彸閿?紝閫夋嫨聽Build Path->Add to Build Path



9.鏈?鍚庡啀淇?敼涓媠rc涓嬬殑Java涓绘枃浠讹紙濡傛灉娌℃湁灏辫嚜宸卞垱寤轰竴涓?級锛屾垜浠??鍋氫互涓嬪嚑浠朵簨锛?/div>
聽1)娣诲姞import com.phonegap.*;
2)鍒犳帀import android.app.Activity;
3)杩樿?寰楀垰鎵嶇殑outer绫讳箞锛熻繖閲屽皢outer缁ф壙涓篋roidGap;
4)鎶妔etContentView()杩欒?鏇挎崲涓簊uper.loadUrl("file:///android_asset/www/index.html");
5)鏈?鍚庣湅璧锋潵灏卞儚杩欐牱锛?/div>

澶嶅埗浠g爜
package com.example.shawn;import android.os.Bundle;import org.apache.cordova.*;public class outer extends DroidGap {    @Override    public void onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        super.loadUrl("file:///android_asset/www/index.html");    }}
澶嶅埗浠g爜

package com.example.shawn;杩欏彞璇濇槸骞插槢鐨勫憿锛熻繖鏄痡ava涓?父鐢ㄧ殑锛岀被浼间簬鏂囦欢鐨勫?姘忥紝鐪嬬湅鏂囦欢鏍戝氨鐭ラ亾浜嗭紝杩欐槸鏀惧湪鏂囦欢鍓嶉潰瀹氫綅鐢ㄧ殑銆?br>



public class outer extends DroidGap;杩欓噷灏唎uter绫荤户鎵夸负DroidGap锛屽悓鏃舵湰鏂囦欢鐨勬枃浠跺悕涔熻?娉ㄦ剰淇濇寔涓?鑷达紙outer.java锛夛紝鍚﹀垯浼氭姤閿欍??/span>

super.loadUrl("file:///android_asset/www/index.html");杩欏彞璇濆ぇ瀹跺彲浠ョ悊瑙d负鍔犺浇涓?涓?綉椤碉紝杩欎釜璺?緞澶у?寰堢啛鎮夛紝灏辨槸鎴戜滑鐨勯?椤点?傞?忚繃杩欏彞璇濇垜浠?篃鍙?互鐪嬪埌phoneGap鏈?鏍规湰鐨勪笢瑗匡紝灏辨槸鍦ㄥ師鐢熻?瑷?涓庣綉椤佃?瑷?涔嬮棿鏋朵竴搴фˉ銆?/span>

鐒跺悗灏卞彲浠ュ湪妯℃嫙鍣ㄤ笅璇曠潃杩愯?涓?涓嬭繖涓?」鐩?紝鎴愬姛鐨勮瘽浼氬嚭鐜癏ello World鐨勭晫闈???/p>



ok浜嗭紝鑷虫?涓烘?锛宲honegap鐨刟ndroid寮?鍙戠幆澧冨氨鎼?缓濂戒簡锛屾偍鍙?互鍩轰簬phonegap缂栧啓鑷?繁鐨刟ndroid搴旂敤浜嗭紒

  相关解决方案