Andoird uses a different traditional Java JNI method to define its native function.

Source: Internet
Author: User

Andoird uses a different traditional Java
JNI is used to define native functions. The important difference is that andorid uses a Java and C
The ing table array of the function, and describes the parameters and return values of the function. The type of this array is jninativemethod, which is defined as follows:

 

Typedef struct {
Const char * Name;
Const char * signature;
Void * fnptr;
} Jninativemethod;

The first variable name is the name of the function in Java.

The second variable signature describes the parameters and return values of the function using a string.

The third variable fnptr is the function pointer pointing to the C function.

 

The second parameter is hard to understand, for example

"() V"

"(Ii) V"

"(Ljava/lang/string;) V"

 

In fact, these characters correspond to the function parameter types one by one.

The character in "()" represents a parameter, and the subsequent character represents the return value. For example, "() V" indicates void func ();

"(Ii) V" indicates void func (INT, INT );

 

The relationship between each character is as follows:

 

Character Java type C
Type

V void
Z jboolean Boolean
I jint int
J jlong long
D jdouble double
F jfloat float
B jbyte byte
C jchar char
S jshort short

 

The array starts with "[" and is represented by two characters.

 

[I jintarray int []
[F jfloatarray float []
[B jbytearray byte []
[C jchararray char []
[S jshortarray short []
[D jdoublearray double []
[J jlongarray long []
[Z jbooleanarray Boolean []

 

The above are all basic types. If the Java function parameter is a class, it starts with "L" and ends with ";" and uses "/" in the middle "/"
The names of packages and classes. The parameter of the corresponding C function name is jobject. An exception is the string class, and its corresponding class is jstring.

 

Ljava/lang/string; string jstring
Ljava/NET/socket; socket jobject

 

If a Java function is located in an embedded class, $ is used as the delimiter between class names.

For example, "(ljava/lang/string; landroid/OS/fileutils $ filestatus;) z"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.