2011/11/26

Git ABC

Install Git on Mac
http://code.google.com/p/git-osx-installer/

Install Git on Windows
http://code.google.com/p/msysgit/

Git Doc
http://git-scm.com/documentation

Map on Android

A simple example:
http://developer.android.com/resources/tutorials/views/hello-mapview.html

About Drop a Pin to map:
http://stackoverflow.com/questions/6545027/how-to-drop-a-pin-on-google-map-and-how-to-get-current-address-in-dialog-box-on
http://stackoverflow.com/questions/3636702/how-do-i-drop-spots-on-google-map-in-an-android-app
http://stackoverflow.com/questions/2683287/drop-pin-on-default-google-maps-from-my-app-in-android

Find a location
http://androidcookbook.com/Recipe.seam?recipeId=1454

Find MD5 of my key:
keytool -list -keystore /Users/noguxun/.android/debug.keystore -alias androiddebugkey
The password is "android".

Sign the key:
http://code.google.com/android/maps-api-signup.html

Good Tutorial:
http://www.vogella.de/articles/AndroidLocationAPI/article.html

Distance:
http://stackoverflow.com/questions/3759680/android-how-to-detect-if-users-if-within-distance-of-geopoint-on-mapview
http://stackoverflow.com/questions/6283028/distance-of-two-geo-point-android

2011/11/22

Get Thread JNIEnv

This is an example shows how:

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { cached_jvm = jvm; /* cache the JavaVM pointer */ return JNI_VERSION_1_2; } static void Some_Function() { (*cached_jvm)->AttachCurrentThread(cached_jvm, &env, NULL); (*env)->MonitorEnter(env, callbackInst); jclass cls = (*env)->GetObjectClass(env, callbackInst); jmethodID id = (*env)->GetMethodID(env, cls, "callback", "(I)V"); (*env)->CallVoidMethod(env, callbackInst, id, (int)l); (*env)->MonitorExit(env, callbackInst); }

2011/08/29

How to get device vender ID

To get the vendor ID of a USB device on Linux "lsusb" will tell you what's what:

steve@media:~/android-sdk-linux/tools$ lsusb
Bus 002 Device 003: ID 045e:0040 Microsoft Corp. Wheel Mouse Optical
Bus 002 Device 002: ID 046d:c315 Logitech, Inc. Classic New Touch Keyboard
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 011: ID 18d1:4e12
Bus 001 Device 006: ID 04b8:011f Seiko Epson Corp. Perfection 1670
Bus 001 Device 003: ID 1058:1003 Western Digital Technologies, Inc.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

2011/08/24

How to say n^m

N的2次方: N Squared
N的3次方: N Cubed
N的M次方: N the M power

N开M次方: the M root of N

2011/08/15

CheckJNI of NewStringUTF

In file Check dalvik/vm/checkjni.c

This is the function which check the input string of NewStringUTF is a valid UTF8 or not.
If not valid, the check function will abort the VM.
That caused our application got crashed when there are some mal-formated UTF8 string.

/* * Verify that "bytes" points to valid "modified UTF-8" data. */ static void checkUtfString(JNIEnv* env, const char* bytes, bool nullOk, const char* func) { const char* origBytes = bytes; if (bytes == NULL) { if (!nullOk) { LOGW("JNI WARNING: unexpectedly null UTF string\n"); goto fail; } return; } while (*bytes != '\0') { u1 utf8 = *(bytes++); // Switch on the high four bits. switch (utf8 >> 4) { case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: { // Bit pattern 0xxx. No need for any extra bytes. break; } case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0f: { /* * Bit pattern 10xx or 1111, which are illegal start bytes. * Note: 1111 is valid for normal UTF-8, but not the * modified UTF-8 used here. */ LOGW("JNI WARNING: illegal start byte 0x%x\n", utf8); goto fail; } case 0x0e: { // Bit pattern 1110, so there are two additional bytes. utf8 = *(bytes++); if ((utf8 & 0xc0) != 0x80) { LOGW("JNI WARNING: illegal continuation byte 0x%x\n", utf8); goto fail; } // Fall through to take care of the final byte. } case 0x0c: case 0x0d: { // Bit pattern 110x, so there is one additional byte. utf8 = *(bytes++); if ((utf8 & 0xc0) != 0x80) { LOGW("JNI WARNING: illegal continuation byte 0x%x\n", utf8); goto fail; } break; } } } return; fail: LOGW(" string: '%s'\n", origBytes); showLocation(dvmGetCurrentJNIMethod(), func); abortMaybe(); }

Android CheckJNI

CheckJNI can catch a number of common errors.

A simple way to enable or disable JNI:
adb remount
adb pull /system/build.prop .

delete or add line ro.kernel.android.checkjni=1

adb push build.prop /system/.
adb shell reboot



Reference:
http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...