• PhoneGap android环境设置


    一. 安装SDK + Cordova 

    二、搭建环境

    配置环境变量

      

      

    三、Eclipse建立工程

    1、新建普通android工程,New > Android Project

    在根目录下新建

    • /libs
    • assets/www

    拷贝PhoneGap中的资料

    • 拷贝cordova-2.5.0.js 到 assets/www
    • 拷贝cordova-2.5.0.jar到/libs
    • 拷贝xml文件夹 /res
    • 拷贝android文件夹到/libs

     建立build Path,鼠标右键单击/libs文件夹,并选择 Build Paths/ > Configure Build Path...

    修改MainActivity

    完整代码为 

    package com.hellocordova;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import org.apache.cordova.DroidGap;
    
    public class MainActivity extends DroidGap {
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		super.loadUrl("file:///android_asset/www/index.html");		
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    }
    

    鼠标右键AndroidManifest.xml文件并选择Open With > XML Editor

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.hellocordova"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="5"
            android:targetSdkVersion="15" />
        <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" />
        
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.hellocordova.MainActivity"
                android:label="@string/app_name"
                android:configChanges="orientation|keyboardHidden" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>

    在<uses-sdk和<application之间加入代码,同时为 <activity>标签加入属性

    android:configChanges="orientation|keyboardHidden"

    assets/www中创建index.html文件,写入以下代码

    <!DOCTYPE HTML>
    <html>
    <head>
    <title>Cordova</title>
    <script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
    </head>
    <body>
    <h1>Hello World</h1>
    </body>
    </html>

     在模拟器中运行,Run As > Android Application

  • 相关阅读:
    Python的简单介绍/解释器/变量/变量的数据类型/用户交互及流程控制(if)
    变量
    hello python
    页面默认值显示
    java 获取时间区间
    java Set 中 removeAll 与 addAll
    命名的数据库实例
    linux 打包与解包
    缓存工作原理
    java 格式化日期(转)
  • 原文地址:https://www.cnblogs.com/JoannaQ/p/2970374.html
Copyright © 2020-2023  润新知