Android 在C代碼中調用logcat,androidlogcat

來源:互聯網
上載者:User

Android 在C代碼中調用logcat,androidlogcat

本文給《Android java傳遞int類型數組給C》中添加C代碼中調用logcat的功能

Android.mk檔案增加以下內容

LOCAL_LDLIBS += -llog

C代碼中增加以下內容

#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的宏定義 起別名 #define LOG_TAG "System.out" 給"System.out"起別名LOG_TAG

#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
給 __android_log_print函數起別名 寫死了前兩個參數 第一個參數 優先順序 第二個參數TAG  __VA_ARGS__ 可變參數的固定寫法
LOGI(...)在調用的時候 用法跟printf()一樣

 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; }

擷取更多C語言與演算法相關知識,關注公眾號:“csuanfa”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.