Android calls Logcat in C code

Source: Internet
Author: User

This article gives the Android java pass int type array to C toadd the function of calling Logcat in C code

ANDROID.MK file Add the following content

Local_ldlibs + =-llog

Add the following in 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's macro defines the alias #define Log_tag "System.out" to "System.out" Alias Log_tag

#define Logi (...) __android_log_print (Android_log_info, Log_tag, __va_args__)
Alias to the __android_log_print function dead first two parameters precedence of the second parameter tag __va_args__ a fixed notation for variable parameters
Logi (...) Use the same as printf () when calling.

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); inti;  for(i =0; i < Len; i++){          * (Arraypointer + i) + =Ten; }      returnJarray;}

Get more knowledge of C language and algorithms, follow the public number: "Csuanfa"

Android calls Logcat in C code

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.