2011年2月12日 星期六

Android JNI 中印 msg 到 Logcat

其實這滿簡單的

新增一個 debug.h

內容如下

#include <android/log.h>

#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG  , "TAG", __VA_ARGS__)
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "TAG",__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "TAG",__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, "TAG",__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "TAG",__VA_ARGS__)

五個 function 分別對應到 5 個 level 的 MSG

在Android.mk 中加上

LOCAL_LDLIBS :=  -L$(SYSROOT)/usr/lib -llog

接著在自己的 c 檔案裡面加上 #include "debug.h"

後來只要用 LOGE("error");

就可以印出來了

2011年2月11日 星期五

Android 中使用 Camera

1. 在 AndroidManifest.xml 中加上 permission 和 feature

<uses-permission android:name="android.permission.CAMERA">
<uses-feature android:name="android.hardware.camera">
<uses-feature android:name="android.hardware.camera.autofocus">


2. 再來在 layout 中加上 SurfaceView


<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="320px"
android:layout_height="240px">
</SurfaceView>

3. 程式碼

參考 Android SDK 網頁
http://developer.android.com/reference/android/hardware/Camera.html
下面是範例code