android中Sensor工作流程(4)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-26 21:59 点击:次
private static native ParcelFileDescriptor _sensors_control_open();
private static native boolean _sensors_control_activate(int sensor, boolean activate);
private static native int _sensors_control_set_delay(int ms);
private static native int _sensors_control_wake();
native 方法
1. manager 部分
frameworks/base/core/jni/android_hardware_SensorManager.cpp
先看一眼它的方法注册
static JNINativeMethod gMethods[] = {
{"nativeClassInit", "()V", (void*)nativeClassInit },
{"sensors_module_init","()I", (void*)sensors_module_init },
{"sensors_module_get_next_sensor","(Landroid/hardware/Sensor;I)I",
(void*)sensors_module_get_next_sensor },
{"sensors_data_init", "()I", (void*)sensors_data_init },
{"sensors_data_uninit", "()I", (void*)sensors_data_uninit },
{"sensors_data_open", "(Ljava/io/FileDescriptor;)I", (void*)sensors_data_open },
{"sensors_data_close", "()I", (void*)sensors_data_close },
{"sensors_data_poll", "([F[I[J)I", (void*)sensors_data_poll },
};
小贴一个例子作为代表
static jint
sensors_data_open(JNIEnv *env, jclass clazz, jobject fdo)
{
jclass FileDescriptor = env->FindClass("java/io/FileDescriptor");
jfieldID offset = env->GetFieldID(FileDescriptor, "descriptor", "I");
int fd = env->GetIntField(fdo, offset);
return sSensorDevice->data_open(sSensorDevice, fd); // doesn't take ownership of fd
}
调用到最后其实都是用的 sSensorDevice 的方法
/*
* The method below are not thread-safe and not intended to be
*/
static sensors_data_device_t* sSensorDevice = 0;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>