Android calls logcat and androidlogcat in C code

Source: Internet
Author: User

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"

Related Article

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.