Implement interaction between C/C ++ and Android Java-layer functions through JNI

Source: Internet
Author: User

This article from: http://codingnow.cn/cocos2d-x/992.html

Abstr:This article mainly implements two functions: (1) obtain the packagename of the application through the android sdk api, and then pass it to the C ++ layer function. (2) Call the Java-layer function of Android through the C ++ function. A dialog box is displayed, and click the button to exit the program. 1. First, let's take a simple look at the knowledge of JNI. In this article, I have implemented how to call C ++ functions on the android Java layer. To use JNI, you must...

This article mainly implements two functions:
(1) obtain the packagename of the application through the android sdk api, and then pass it to the C ++ layer function.
(2) Call the Java-layer function of Android through the C ++ function. A dialog box is displayed, and click the button to exit the program.

1. First, let's take a simple look at the knowledge of JNI. In this article, I have implemented how to call C ++ functions on the android Java layer. To use JNI, the header file must be included. Android uses ndk to compile C/C ++. Here, JNI. h file is located in: \ android-ndk-r8b \ platforms \ Android-14 \ arch-Arm \ USR \ include \ JNI. h. This file defines all JNI-related data types and interfaces. The following is a code snippet:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 #
include <inttypes.h>      /* C99 */
typedefuint8_t        
jboolean;      
/*
unsigned 8 bits */
typedefint8_t         
jbyte;         
/*
signed 8 bits */
typedefuint16_t       
jchar;         
/*
unsigned 16 bits */

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.