android runtime保存日志,android - Runtime.getRuntime().exec("logcat -d") returns null - Stack Overflow...

I'm trying to get the log of my app. Android 4.1.2 (Huawei tablet)

This is the code that I'm using

StringBuilder log=new StringBuilder();

try {

Process process = Runtime.getRuntime().exec("logcat -d");

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

String line;

while ((line = bufferedReader.readLine()) != null) {

log.append(line);

log.append(System.getProperty("line.separator"));

}

System.out.println(line == null);

} catch (IOException e) {

System.out.println("error");

e.printStackTrace();

}

I have added ther permissions to manifest

When I try to read it bufferedReader is null and nothing is added to log variable.

EDIT:

I've founded this info

Apparently Huawei devices have service loggin disabled by default. I've tried the solution of the post but it doesn't work for me because "service loggin" option doesn't appears

Can someone help me?

Thanks

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用提到了Runtime.getRuntime().exec()方法,该方法可以在Android中执行命令或创建进程。根据引用,您可以使用这种方法从Java代码中调用Python脚本。但需要注意的是,引用指出正确的写法应该是Runtime.getRuntime()而不是getruntime。因此,根据您的问题"android8 Runtime.getRuntime().exec",您可以使用以下代码来执行命令或创建进程: ```java Runtime runtime = Runtime.getRuntime(); String command = "your_command_here"; try { Process process = runtime.exec(command); // 处理进程的输出或其他操作 } catch (IOException e) { e.printStackTrace(); } ``` 在上述代码中,将"your_command_here"替换为您要执行的具体命令。这样,您就可以在Android 8及以上版本中使用Runtime.getRuntime().exec()方法执行命令或创建进程了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [使用runtime.getruntime.exec从Java调用python脚本(Calling python script from Java using runtime....](https://blog.csdn.net/weixin_39618730/article/details/110567660)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [Android Runtime.getRuntime().exec()](https://blog.csdn.net/xianrenli38/article/details/117484708)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值