Android calls logcat and androidlogcat in C code
This article adds the function of calling logcat in C code to "passing an array of int type to C in Android java ".
Add the following content to the Android. mk file:
LOCAL_LDLIBS + =-llog
Add the following content to the C code:
#include <android/log.h>#define LOG_TAG "System.out"#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
Define C macro definition alias # define LOG_TAG "System. out" to "System. out" alias LOG_TAG
# Define LOGI (...) _ android_log_print (ANDROID_LOG_INFO, LOG_TAG, _ VA_ARGS __)
The alias for the _ android_log_print function is written to the first two parameters, the first parameter priority, and the second parameter TAG _ VA_ARGS _ variable parameter.
LOGI (...) is used in the same way as printf () when called.
JNICALL Java_com_wuyudong_javapassdata_JNI_arrElementsIncrease( JNIEnv * env, jobject clazz, jintArray jArray){ jsize len = (*env)->GetArrayLength(env, jArray); LOGD("length = %d", len); // jboolean iscopy; int* arrayPointer = (*env)->GetIntArrayElements(env, jArray, NULL); int i; for(i = 0; i < len; i++){ *(arrayPointer + i) += 10; } return jArray; }
To learn more about C language and algorithms, follow the Public Account "csuanfa"