Show pageOld revisionsBacklinksAdd to bookExport to PDFBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Cordova ====== ===== Install ===== Install nodejs and npm <code> sudo apt-get install nodejs npm </code> Install cordova <code> sudo npm install -g cordova </code> cordova need node and ubuntu install nodejs <code> sudo ln -s /usr/bin/nodejs /usr/local/bin/node </code> install cordova-browser from git to have linux support <code> sudo npm install -g git://git.apache.org/cordova-browser.git </code> ===== Update ===== <code> sudo npm update -g </code> ===== Install Android SDK ===== Create /etc/etc/profile.d/android.sh or add in .bash_profile <code> export ANDROID_HOME=/lab/android-sdk-linux/ export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools </code> ===== Project ===== ==== Create project ==== <code> cordova create /lab/peper-memory org.csgalileo.peper.memory PeperMemory </code> Add android support <code> cd /lab/peper-memory cordova platform list cordova platforms add android cordova platforms add browser # temporary patch # cp /usr/local/lib/node_modules/cordova-browser/bin/templates/project/cordova/run ./platforms/browser/cordova/run </code> Add to platforms/browser/cordova/run <code> case 'linux': spawn('chromium-browser', ['--test-type', '--disable-web-security', '--user-data-dir=/tmp/temp_chrome_user_data_dir_for_cordova_browser', project]); break; </code> ==== Crosswalk ==== Optionally it is possible to use crosswalk instead of android webview Add android platform to project <code> cordova platforms add android </code> Download [https://crosswalk-project.org/documentation/downloads.html|crosswalk] <code> CROSSWALK=/lab/crosswalk/crosswalk-cordova-10.39.235.15-arm rm -fR platforms/android/CordovaLib/* cp -a ${CROSSWALK}/framework/* platforms/android/CordovaLib/ cp -a ${CROSSWALK}/VERSION platforms/android/ </code> Add to platforms/android/AndroidManifest.xml <code> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> </code> Build both the CordovaLib and xwalk_core_library <code> cd platforms/android/CordovaLib/ android update project --subprojects --path . --target "android-19" ant clean debug cd .. # platforms/android/ rm -Rf ant-gen rm -Rf ant-build cd ../.. cordova build android </code> ==== Manage project ==== View project detail <code> cordova info </code> Add plugins <code> cordova plugin add org.apache.cordova.device cordova plugin add org.apache.cordova.console # cordova plugin add https://github.com/donaldp24/CanvasCameraPlugin.git && cordova prepare </code> Search plugins <code> cordova plugin search <text> </code> Update corbova inside project <code> cordova platform update android </code> ==== Test project ==== <code> cordova emulate browser </code> ==== Release ==== <code> cordova build --release android </code> [http://developer.android.com/tools/publishing/app-signing.html sign and align] ===== Video autoplay ===== Con ionic-crosswalk i video partono da soli con il set di src via javascript <code javascript> if (! $('#video1')[0].src) { $('#video1')[0].src = "http://..."; } $("#video1")[0].currentTime = 0; // rewind $("#video1")[0].play(); </code> ==== Cordova ==== CordovaApp.java <code> super.init(); super.appView.getSettings().setMediaPlaybackRequiresUserGesture(false); </code> ==== Cordova Crosswalk ==== <code> ... super.init(); getSettings(super.appView).setMediaPlaybackRequiresUserGesture(false); ... /* rende plubblica la API mascherata dalle nuove release di crosswalk */ private XWalkSettings getSettings(XWalkView webView) { try { Method ___getBridge = XWalkView.class.getDeclaredMethod("getBridge"); ___getBridge.setAccessible(true); XWalkViewBridge xWalkViewBridge = null; xWalkViewBridge = (XWalkViewBridge)___getBridge.invoke(webView); XWalkSettings xWalkSettings = xWalkViewBridge.getSettings(); return xWalkSettings; } catch (Exception e) { e.printStackTrace(); } return null; } </code> Posizionare un set di src dopo il device ready <code> $('#video1')[0].src = "http://192.168.2.125:8000/lib/exe/fetch.php?media=contrade:pergari:pergari_int.webm"; </code> ===== GPIO ===== jni contain NDK project <code> ├── Android.mk ├── gpio.c ├── gpio.h └── jni_gpio.c </code> Rebuild this project running '''ndk-build into jni folde'''r Android.mk <code> LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := gpio_test LOCAL_SRC_FILES := gpio.c LOCAL_LDLIBS += -llog LOCAL_CFLAGS += -DEXEC include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) LOCAL_MODULE := libgpio LOCAL_SRC_FILES := gpio.c jni_gpio.c LOCAL_LDLIBS += -llog include $(BUILD_SHARED_LIBRARY) </code> gpio.c <code> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <poll.h> #include <fcntl.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> #include "gpio.h" #define LOG_TAG "GPIO" #ifndef EXEC #include <android/log.h> #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #else #define LOGD(...) printf(">==< %s >==< ",LOG_TAG),printf(__VA_ARGS__),printf("\n") #endif void on_new_value(int val); int read_gpio(char *path, void (*callback)(int)); int main(int argc, char **argv){ LOGD("Hello!\n"); #ifdef HOST return 0; #endif if(argc == 2) return read_gpio(argv[1], on_new_value); else LOGD("missing argument path"); return -1; } int read_gpio(char *path, void (*callback)(int)){ int fd = open(path, O_RDONLY); char buf[11]; int res = 0; if(fd == -1){ perror("error opening file"); return -1; } struct pollfd gpio_poll_fd = { .fd = fd, .events = POLLPRI, .revents = 0 }; for(;;){ res = poll(&gpio_poll_fd,1,-1); if(res == -1){ perror("error polling"); break; } if((gpio_poll_fd.revents & POLLPRI) == POLLPRI){ LOGD("POLLPRI"); int off = lseek(fd, 0, SEEK_SET); if(off == -1) break; memset(&buf[0], 0, 11); size_t num = read(fd, &buf[0], 10*sizeof(char)); callback(atoi(buf)); } if((gpio_poll_fd.revents & POLLERR) == POLLERR){ //seems always to be true .. //LOGD("POLLERR"); } } return 0; } void on_new_value(int val){ LOGD("interrupt received, val: %d", val); } </code> gpio.h <code> #ifndef _GPIO_H_ #define _GPIO_H_ int read_gpio(char *path, void (*callback)(int)); #endif </code> jni_gpio.c <code> #include <jni.h> #include <stdlib.h> /* Header for class nativehelper_NativeGpio */ #include "gpio.h" #define LOG_TAG "GPIO" #ifndef HOST #include <android/log.h> #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #else #define LOGD(...) printf(">==< %s >==< ",LOG_TAG),printf(__VA_ARGS__),printf("\n") #endif #ifndef _Included_nativehelper_NativeGpio #define _Included_nativehelper_NativeGpio #endif #ifdef __cplusplus extern "C" { #endif static void on_new_value(int val); static jmethodID cb_method_id; static jclass cb_class; static jobject cb_object; static JNIEnv *cb_save_env; /* * Class: csgalileo_NativeGpio * Method: readGpio * Signature: (Ljava/lang/String;Lcsgalileo/NativeGpio/GpioInterruptCallback;)V */ JNIEXPORT void JNICALL Java_csgalileo_NativeGpio_readGpio (JNIEnv *env, jclass cls, jstring path, jobject callback){ cb_class = (*env)->GetObjectClass(env, callback); if(cb_class == NULL){ LOGD("callback interface not found"); return; } cb_method_id = (*env)->GetMethodID(env, cb_class, "onNewValue", "(I)V"); if(cb_method_id == NULL){ LOGD("could not find callback method"); return; } cb_object = callback; cb_save_env = env; const char *fname = (*env)->GetStringUTFChars(env, path, NULL); LOGD("path is %s", fname); read_gpio((char *)fname, on_new_value); (*env)->ReleaseStringUTFChars(env, path, fname); } static void on_new_value(int val){ LOGD("on_new_value interrupt received, val: %d", val); (*cb_save_env)->CallVoidMethod(cb_save_env, cb_object, cb_method_id, (jint)val); } #ifdef __cplusplus } #endif </code> tips/cordova.txt Last modified: 2015/02/19 17:10by scipio