【Android】 C/C++ 标准输入输出打印至Android日志控制台
#if defined(__ANDROID__)
start_logger("sdk-native");
#endif
#if defined(__ANDROID__)
#include <stdio.h>
#include <unistd.h>
#include <android/log.h>
#include <android/native_activity.h>
#include <android/asset_manager_jni.h>
#include <android/asset_manager.h>
#endif
#if defined(__ANDROID__)
extern "C" {
static int pfd[2];
static pthread_t thr;
static const char *tag = "myapp";
static void *thread_func(void *)
{
ssize_t rdsz;
char buf[128];
while ((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
if (buf[rdsz - 1] == '\n') --rdsz;
buf[rdsz] = 0; /* add null-terminator */
__android_log_write(ANDROID_LOG_DEBUG, tag, buf);
}
return 0;
}
int start_logger(const char *app_name)
{
tag = app_name;
/* make std