1.参考官方文档

http://docs.oracle.com/javase/7/docs/technotes/guides/jni/

http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html

http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html

3.函数列表

 typedef const struct JNINativeInterface *JNIEnv;
const struct JNINativeInterface ... = { NULL,
NULL,
NULL,
NULL,
GetVersion, DefineClass,
FindClass, FromReflectedMethod,
FromReflectedField,
ToReflectedMethod, GetSuperclass,
IsAssignableFrom, ToReflectedField, Throw,
ThrowNew,
ExceptionOccurred,
ExceptionDescribe,
ExceptionClear,
FatalError, PushLocalFrame,
PopLocalFrame, NewGlobalRef,
DeleteGlobalRef,
DeleteLocalRef,
IsSameObject,
NewLocalRef,
EnsureLocalCapacity, AllocObject,
NewObject,
NewObjectV,
NewObjectA, GetObjectClass,
IsInstanceOf, GetMethodID, CallObjectMethod,
CallObjectMethodV,
CallObjectMethodA,
CallBooleanMethod,
CallBooleanMethodV,
CallBooleanMethodA,
CallByteMethod,
CallByteMethodV,
CallByteMethodA,
CallCharMethod,
CallCharMethodV,
CallCharMethodA,
CallShortMethod,
CallShortMethodV,
CallShortMethodA,
CallIntMethod,
CallIntMethodV,
CallIntMethodA,
CallLongMethod,
CallLongMethodV,
CallLongMethodA,
CallFloatMethod,
CallFloatMethodV,
CallFloatMethodA,
CallDoubleMethod,
CallDoubleMethodV,
CallDoubleMethodA,
CallVoidMethod,
CallVoidMethodV,
CallVoidMethodA, CallNonvirtualObjectMethod,
CallNonvirtualObjectMethodV,
CallNonvirtualObjectMethodA,
CallNonvirtualBooleanMethod,
CallNonvirtualBooleanMethodV,
CallNonvirtualBooleanMethodA,
CallNonvirtualByteMethod,
CallNonvirtualByteMethodV,
CallNonvirtualByteMethodA,
CallNonvirtualCharMethod,
CallNonvirtualCharMethodV,
CallNonvirtualCharMethodA,
CallNonvirtualShortMethod,
CallNonvirtualShortMethodV,
CallNonvirtualShortMethodA,
CallNonvirtualIntMethod,
CallNonvirtualIntMethodV,
CallNonvirtualIntMethodA,
CallNonvirtualLongMethod,
CallNonvirtualLongMethodV,
CallNonvirtualLongMethodA,
CallNonvirtualFloatMethod,
CallNonvirtualFloatMethodV,
CallNonvirtualFloatMethodA,
CallNonvirtualDoubleMethod,
CallNonvirtualDoubleMethodV,
CallNonvirtualDoubleMethodA,
CallNonvirtualVoidMethod,
CallNonvirtualVoidMethodV,
CallNonvirtualVoidMethodA, GetFieldID, GetObjectField,
GetBooleanField,
GetByteField,
GetCharField,
GetShortField,
GetIntField,
GetLongField,
GetFloatField,
GetDoubleField,
SetObjectField,
SetBooleanField,
SetByteField,
SetCharField,
SetShortField,
SetIntField,
SetLongField,
SetFloatField,
SetDoubleField, GetStaticMethodID, CallStaticObjectMethod,
CallStaticObjectMethodV,
CallStaticObjectMethodA,
CallStaticBooleanMethod,
CallStaticBooleanMethodV,
CallStaticBooleanMethodA,
CallStaticByteMethod,
CallStaticByteMethodV,
CallStaticByteMethodA,
CallStaticCharMethod,
CallStaticCharMethodV,
CallStaticCharMethodA,
CallStaticShortMethod,
CallStaticShortMethodV,
CallStaticShortMethodA,
CallStaticIntMethod,
CallStaticIntMethodV,
CallStaticIntMethodA,
CallStaticLongMethod,
CallStaticLongMethodV,
CallStaticLongMethodA,
CallStaticFloatMethod,
CallStaticFloatMethodV,
CallStaticFloatMethodA,
CallStaticDoubleMethod,
CallStaticDoubleMethodV,
CallStaticDoubleMethodA,
CallStaticVoidMethod,
CallStaticVoidMethodV,
CallStaticVoidMethodA, GetStaticFieldID, GetStaticObjectField,
GetStaticBooleanField,
GetStaticByteField,
GetStaticCharField,
GetStaticShortField,
GetStaticIntField,
GetStaticLongField,
GetStaticFloatField,
GetStaticDoubleField, SetStaticObjectField,
SetStaticBooleanField,
SetStaticByteField,
SetStaticCharField,
SetStaticShortField,
SetStaticIntField,
SetStaticLongField,
SetStaticFloatField,
SetStaticDoubleField, NewString, GetStringLength,
GetStringChars,
ReleaseStringChars, NewStringUTF,
GetStringUTFLength,
GetStringUTFChars,
ReleaseStringUTFChars, GetArrayLength, NewObjectArray,
GetObjectArrayElement,
SetObjectArrayElement, NewBooleanArray,
NewByteArray,
NewCharArray,
NewShortArray,
NewIntArray,
NewLongArray,
NewFloatArray,
NewDoubleArray, GetBooleanArrayElements,
GetByteArrayElements,
GetCharArrayElements,
GetShortArrayElements,
GetIntArrayElements,
GetLongArrayElements,
GetFloatArrayElements,
GetDoubleArrayElements, ReleaseBooleanArrayElements,
ReleaseByteArrayElements,
ReleaseCharArrayElements,
ReleaseShortArrayElements,
ReleaseIntArrayElements,
ReleaseLongArrayElements,
ReleaseFloatArrayElements,
ReleaseDoubleArrayElements, GetBooleanArrayRegion,
GetByteArrayRegion,
GetCharArrayRegion,
GetShortArrayRegion,
GetIntArrayRegion,
GetLongArrayRegion,
GetFloatArrayRegion,
GetDoubleArrayRegion,
SetBooleanArrayRegion,
SetByteArrayRegion,
SetCharArrayRegion,
SetShortArrayRegion,
SetIntArrayRegion,
SetLongArrayRegion,
SetFloatArrayRegion,
SetDoubleArrayRegion, RegisterNatives,
UnregisterNatives, MonitorEnter,
MonitorExit, GetJavaVM, GetStringRegion,
GetStringUTFRegion, GetPrimitiveArrayCritical,
ReleasePrimitiveArrayCritical, GetStringCritical,
ReleaseStringCritical, NewWeakGlobalRef,
DeleteWeakGlobalRef, ExceptionCheck, NewDirectByteBuffer,
GetDirectBufferAddress,
GetDirectBufferCapacity, GetObjectRefType
};

4.常用函数表

对象(全局和局部)的生成,删除.
jobject NewGlobalRef(JNIEnv *env, jobject obj);

Creates a new global reference to the object referred to by the obj argument.

The obj argument may be a global or local reference. Global references must be explicitly disposed

of by calling DeleteGlobalRef().

void DeleteGlobalRef(JNIEnv *env, jobject globalRef); Deletes the global reference pointed to by globalRef.
jobject NewLocalRef(JNIEnv *env, jobject ref);

Creates a new local reference that refers to the same object as ref. The given ref may be a global or

local reference. Returns NULL if ref refers to null.

void DeleteLocalRef(JNIEnv *env, jobject localRef); Deletes the local reference pointed to by localRef.
类的定义,声明,查找等
jclass FindClass(JNIEnv *env, const char *name);

The result of ClassLoader.getSystemClassLoader is used. This is the class loader the virtual machine creates

for applications,and is able to locate classes listed in the java.class.path property.

The name argument is a fully-qualified class name or an array type signature .

For example, the fully-qualified class name for the java.lang.String class is:

           "java/lang/String"  

  如   com.txt.Stu 则定成com/txt/Stu ,把包名中的.改成/

The array type signature of the array class java.lang.Object[] is:

        "[Ljava/lang/Object;"

jclass GetSuperclass(JNIEnv *env, jclass clazz);

If clazz represents any class other than the class Object, then this function returns the object that represents

the superclass of the class specified by clazz.If clazz specifies the class Object, or clazz represents an interface,

this function returns NULL.

jclass DefineClass(JNIEnv *env, const char *name,

jobject loader,const jbyte *buf, jsize bufLen);

Loads a class from a buffer of raw class data. The buffer containing the raw class data is

not referenced by the VM after the DefineClass call returns, and it may be discarded if desired.

jobject AllocObject(JNIEnv *env, jclass clazz);

Allocates a new Java object without invoking any of the constructors for the object. Returns a reference to the object.

The clazz argument must not refer to an array class.

jobject NewObject(JNIEnv *env,

jclass clazz,jmethodID methodID, ...);

有3个重载

Constructs a new Java object. The method ID indicates which constructor method to invoke.

This ID must be obtained by calling GetMethodID() with <init> as the method name and void

(V) as the return type.

The clazz argument must not refer to an array class.

数组相关   

ArrayType NewXXXArray(JNIEnv *env,jsize length);

申请数组

A family of operations used to construct a new primitive array object. Table 4-8 describes the specific primitive

array constructors.You should replace NewXXXArray with one of the actual primitive array constructor

routine names from the following table, and replace ArrayType with the corresponding array type for that routine.

NativeType *GetXXXArrayElements(JNIEnv *env,

ArrayType array, jboolean *isCopy);

返回数组所有元素

A family of functions that returns the body of the primitive array. The result is valid until the corresponding

ReleaseXXXArrayElements() function is called. Since the returned array may be a copy of the

Java array, changes made to the returned array will not necessarily be reflected in the original array until

ReleaseXXXArrayElements() is called.

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made;

or it is set to JNI_FALSE if no copy is made.

void ReleaseXXXArrayElements(JNIEnv *env,
ArrayType array, NativeType *elems, jint mode);

A family of functions that informs the VM that the native code no longer needs access to elems. The elems argument

is a pointer derived from array using the corresponding GetXXXArrayElements() function. If necessary, this function

copies back all changes made to elems to the original array.The mode argument provides information on how the array

buffer should be released. mode has no effect if elems is not a copy of the elements in array. Otherwise, mode has the

following impact, as shown in the following table: Table 4-10 Primitive Array Release Modes

mode

actions
0
copy back the content and free the elems buffer
当isCopy是true时,用这个,说明jvm的是返回副本,
把副本的内容更新的源数组,并把副本释放.
JNI_COMMIT
copy back the content but do not free the elems buffer
当isCopy是false时,用这个,说明jvm返回的是引用,
这时不要释放数组.
JNI_ABORT
free the buffer without copying back the possible changes
这是只释放掉缓冲,不更新内容

In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays.

The other options give the programmer more control over memory management and should be used with extreme care.

jsize GetArrayLength(JNIEnv *env, jarray array); Returns the number of elements in the array.

void SetXXXArrayRegion(JNIEnv *env, ArrayType array,

jsize start, jsize len,

const NativeType *buf);

A family of functions that copies back a region of a primitive array from a buffer.The following table describes the

specific primitive array element accessors. You should make the following replacements:

void GetXXXArrayRegion(JNIEnv *env, ArrayType array,

jsize start, jsize len, NativeType *buf);

 A family of functions that copies a region of a primitive array into a buffer.
获取对象属性,成员系列

jclass GetObjectClass(JNIEnv *env, jobject obj);

Returns the class of an object. 

GetMethodID与GetStaticMethodID系列

jmethodID GetMethodID(JNIEnv *env, 
jclass clazz,

const char *name, const char *sig);

Returns the method ID for an instance (nonstatic) method of a class or interface. The method may be defined in one

of the clazz’s superclasses and inherited by clazz. The method is determined by its name and signature.

GetMethodID() causes an uninitialized class to be initialized.

To obtain the method ID of a constructor, supply <init> as the method name and void (V) as the return type.

GetFieldID与GetFieldID系列
jfieldID GetFieldID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);

Returns the field ID for an instance (nonstatic) field of a class. The field is specified by its name and signature.

The Get<type>Field and Set<type>Field families of accessor functions use field IDs to retrieve object fields.

GetFieldID() causes an uninitialized class to be initialized.

GetFieldID() cannot be used to obtain the length field of an array. Use GetArrayLength() instead.

调用系列

NativeType CallXXXMethod(JNIEnv *env,

jobject obj,jmethodID methodID, ...);

使用obj,class,等调用值为methoID的函数.注意要用 jobject,不是jclass

NativeType CallStaticXXXMethod(JNIEnv *env,

jclass clazz,jmethodID methodID, ...);

This family of operations invokes a static method on a Java object, according to the specified method ID.

The methodID argument must be obtained by calling GetStaticMethodID().

The method ID must be derived from clazz, not from one of its superclasses.

字符串相关

jstring NewStringUTF(JNIEnv *env, const char *bytes);

Constructs a new java.lang.String object from an array of characters in modified UTF-8 encoding.

const char * GetStringUTFChars(JNIEnv *env,

jstring string,jboolean *isCopy);

Returns a pointer to an array of bytes representing the string in modified UTF-8 encoding.

This array is valid until it is released by ReleaseStringUTFChars().

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.

环境相关

jint GetJavaVM(JNIEnv *env, JavaVM **vm);

Returns the Java VM interface (used in the Invocation API) associated with the current thread.

The result is placed at the location pointed to by the second argument, vm.

jboolean ExceptionCheck(JNIEnv *env);

Returns JNI_TRUE when there is a pending exception; otherwise, returns JNI_FALSE.

等等 ...

NDK(12)Jni常用函数的更多相关文章

  1. 12. oracle 常用函数

    一.字符函数字符函数是oracle中最常用的函数,我们来看看有哪些字符函数:lower(char):将字符串转化为小写的格式.upper(char):将字符串转化为大写的格式.length(char) ...

  2. 【转】JNI学习积累之一 ---- 常用函数大全

    原文网址:http://blog.csdn.net/qinjuning/article/details/7595104 本文原创,转载请注明出处:http://blog.csdn.net/qinjun ...

  3. JNI学习积累之一 ---- 常用函数大全

    主要资料来源: 百度文库的<JNI常用函数> . 同时对其加以了补充 . 要素  :1. 该函数大全是基于C语言方式的,对于C++方式可以直接转换 ,例如,对于生成一个jstring类型的 ...

  4. Mysql 常用函数(12)- left 函数

    Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html left 的作用 返回字符串 str 中最左边的 ...

  5. Jmeter 常用函数(12)- 详解 __machineName

    如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦 https://www.cnblogs.com/poloyy/p/13291704.html 作用 返回机器(电脑)名称 语法格式 ${_ ...

  6. [ 转载 ] Android JNI(一)——NDK与JNI基础

    Android JNI(一)——NDK与JNI基础 隔壁老李头 关注  4.4 2018.05.09 17:15* 字数 5481 阅读 11468评论 8喜欢 140 本系列文章如下: Androi ...

  7. Android JNI(一)——NDK与JNI基础

    本系列文章如下: Android JNI(一)——NDK与JNI基础 Android JNI学习(二)——实战JNI之“hello world” Android JNI学习(三)——Java与Nati ...

  8. Android(安卓)开发通过NDK调用JNI,使用opencv做本地c++代码开发配置方法 边缘检测 范例代码

    以前写过两个Android开发配置文档,使用NDK进行JNI开发,这样能够利用以前已经写好的C++代码. 前两篇博客地址: http://blog.csdn.net/watkinsong/articl ...

  9. oracle常用函数及示例

    学习oracle也有一段时间了,发现oracle中的函数好多,对于做后台的程序猿来说,大把大把的时间还要学习很多其他的新东西,再把这些函数也都记住是不太现实的,所以总结了一下oracle中的一些常用函 ...

随机推荐

  1. Java 图形编程 一:入门

    package second; import java.awt.Color; import java.awt.Frame; import java.awt.event.WindowAdapter; i ...

  2. 【学习总结】iOS 数据保存几种方式总结

    在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题.将数据保存到本地,能够让程序的运行更加流畅,不会出现让人厌恶的菊花形状,使得用户体验更好.下面介绍一下数据保存的方式: NSKeyedAr ...

  3. cocos2dx中加载图片资源的方法,和从内存中获取已经加载的图片资源的方法

    游戏中通常需要将常用的资源如:声音,图片,plist文件,提前加载进内存,以加快游戏的流畅度 1.预加载声音: SimpleAudioEngine::getInstance()->preload ...

  4. 对frameset、frame、iframe的js操作

    框架编程概述一个HTML页面可以有一个或多个子框架,这些子框架以<iframe>来标记,用来显示一个独立的HTML页面.这里所讲的框架编程包括框架的自我控制以及框架之间的互相访问,例如从一 ...

  5. beego 0.9.0 中智能路由AutoRouter的使用方法及源码解读

    了解beego的开发者肯定知道,beego的路由设计来源于sinatra,原来是不支持自动路由的,每一个路由都要自己配置的,如: type MainController struct { beego. ...

  6. Http之Get/Post请求区别

    Http之Get/Post请求区别 1.HTTP请求格式: <request line> <headers> <blank line> [<request-b ...

  7. ffmpeg 打开视频流太慢(上)

    新版ffmpeg打开网络视频流需要调用avformat_find_stream_info方法,很多朋友会发现调用改方法耗费很多时间造成打开视频流太慢.有两个参数可以减少avformat_find_st ...

  8. 用matlab查找txt文档中的关键字,并把关键字后面的数据存到起来用matlab处理

    用matlab查找txt文档中的关键字,并把关键字后面的数据存到起来用matlab处理 我测了一组数据存到txt文件中,是个WIFI信号强度文档,里面有我们需要得到的数据,有没用的数据,想用matla ...

  9. PV操作,

    P操作是先做减一操作,然后判读是否大于等于0. V操作是先做加一操作,然后判断是否大于0

  10. cf 359A 359B

    359A 如果有点在边上则最少两次 没有则最少操作4次 #include <cstdio> #include <cstring> #include <algorithm& ...