android:Cordova Android, hello Cordova ,PhoneGap android

文章来自:

官方文档:

下载安装nodeJS:https://nodejs.org/下载安装cordova:

$ sudo npm install -g cordova

创建项目:

$ cordova create hello com.example.hello HelloWorld

添加平台支持:$ cordova platform add ios$ cordova platform add amazon-fireos$ cordova platform add android$ cordova platform add blackberry10$ cordova platform add firefoxosAndroid Studio导入项目运行OK.

一路next;可以安装官方 guides 导入android文件夹;

修改界面;

修改assert下 index.html,添加两个button

==/>====>添加js事件;

修改index.js

{document.addEventListener(“deviceready”, handle, false);}{console.log(“deviceready”);document.addEventListener(“resume”,onResume,false);}{showToast(“onResume”);}{var calssName = “”;switch(arg){case ‘web’:calssName = “com.intbird.soft.cordovar.WebViewActivity”break;case ‘camera’:calssName = “com.intbird.soft.cordovar.CameraActivity”;break;default:showToast(‘ERROR’);break;}if(“” != calssName)cordova.exec(resultSuccess,resultError,”CallActivityPlugin”,”call”,[calssName]);}{showToast(“success “+result);}{showToast(“error “+error);}{cordova.exec(null, null, “ToastPlugin”, “toast”, [ message ]);}Plugin插件编写;忽略我将v写成c

如上面的 cordova.exec(null, null, “ToastPlugin”, “toast”, [ message ]);

弹出提示

package com.intbird.soft.cordoca.plugins;import android.widget.Toast;import org.apache.cordova.CallbackContext;import org.apache.cordova.CordovaPlugin;import org.json.JSONArray;import org.json.JSONException;/** * Created by intbird on 15/6/11. */{String ACTION = “toast”;(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {if (action.equals(ACTION)) {Toast.makeText(cordova.getActivity(), args.getString(0), Toast.LENGTH_SHORT).show();}return true;}}

调用Activity

package com.intbird.soft.cordoca.plugins;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import org.apache.cordova.CallbackContext;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.PluginResult;import org.json.JSONArray;import org.json.JSONException;/** * Created by intbird on 15/6/11. */{String ACTION = “call”;(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {if(this.cordova.getActivity().isFinishing()) return true;if(action.equals(ACTION)){try{Intent intent = new Intent(cordova.getActivity(),Class.forName(args.getString(0)));this.cordova.startActivityForResult(this,intent,-1);PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);mPlugin.setKeepCallback(true);callbackContext.sendPluginResult(mPlugin);callbackContext.success(“activity started”);callbackContext.error(“activity not start.”);}catch(Exception ex){ex.printStackTrace();return false;}}return true;}(int requestCode, int resultCode, Intent intent) {switch (resultCode){case Activity.RESULT_OK:Bundle b = intent.getExtras();String str = b.getString(“changge01”);break;default:break;}}}配置插件;

在 res/xml/config.xml中添加feature配置,同时修改背景色和其他标志

==”BackgroundColor” value=”0x00FFFFFF”/>====>A sample Apache Cordova application that responds to the deviceready event.=”dev@cordova.apache.org” href=”http://cordova.io”>Apache Cordova Team========”geo:*” />feature>==>=>=></widget>报错;

06-11 17:47:24.708 12895-12895/com.intbird.soft.cordoca I/chromium﹕ [INFO:CONSOLE(41)] “Refused to execute inline event handler because it violates the following Content Security Policy directive: “default-src ‘self’ data: gap: https://ssl.gstatic.com ‘unsafe-eval’”. Note that ‘script-src’ was not explicitly set, so ‘default-src’ is used as a fallback. “, source: file:///android_asset/www/index.html (41)

-在时光的激流中,我们总会长大。

android:Cordova Android, hello Cordova ,PhoneGap android

相关文章:

你感兴趣的文章:

标签云: