机器人无法从应用程序中运行logcat的 [英] Android unable to run logcat from application
问题描述
所以,我写了需要能够分析会话期间登录异常的探查。我的计划是使用的logcat转储到无论是在SD卡或内部存储,然后在分析会话完成,压缩和解的文件,并在发送至服务器的文件。我加了 android.permission.READ_LOGS
在我的表现,我的code是如下:
So I am writing a profiler that needs to be able to log exceptions during the profiling session. My plan was to use logcat to dump to a file either on the SD card or the internal storage and then when the profiling session was complete, zipping the file up and sending it up to the server. I added the android.permission.READ_LOGS
in my manifest, and my code is as follows:
public void startLoggingExceptions() {
String filename = null;
String directory = null;
String fullPath = null;
String externalStorageState = null;
// The directory will depend on if we have external storage available to us or not
try {
filename = String.valueOf(System.currentTimeMillis()) + ".log";
externalStorageState = Environment.getExternalStorageState();
if (externalStorageState.equals(Environment.MEDIA_MOUNTED)) {
if(android.os.Build.VERSION.SDK_INT <= 7) {
directory = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
directory = ProfilerService.this.getExternalFilesDir(null).getAbsolutePath();
}
} else {
directory = ProfilerService.this.getFilesDir().getAbsolutePath();
}
fullPath = directory + File.separator + filename;
Log.w("ProfilerService", fullPath);
Log.w("ProfilerService", "logcat -f " + fullPath + " *:E");
exceptionLogger = Runtime.getRuntime().exec("logcat -f " + fullPath + " *:E");
} catch (Exception e) {
Log.e("ProfilerService", e.getMessage());
}
}
exceptionLogger是过程的对象,我然后调用 exceptionLogger.destroy()
时分析会话完成。
exceptionLogger is a Process object, which I then call exceptionLogger.destroy()
on when the profiling session is complete.
我看到的行为是该文件被创建,我指定但从来没有在文件中任何日志输出。我使用的开发工具的应用程序在仿真器来强制未处理的异常显示在日志中,但我的logcat的输出文件是空的。有什么想法?
The behavior I am seeing is that the file is created where I specify but there is never any logging output in the file. I am using the dev tools application in the emulator to force an unhandled exception to show up in the logs, but my logcat output file remains empty. Any thoughts?
编辑:所以,当我进入亚行的shell,然后SU到分配给我的应用程序的用户帐户,我看到下面的运行logcat的时候:
So when I go into the adb shell, and then SU to the user account that is assigned to my application, I see the following when running logcat:
Unable to open log device '/dev/log/main': Permission denied
我原以为加入清单允许我的应用程序,然后将允许我这样做?
I had thought that adding the manifest permission to my app would then allow me to do this?
推荐答案
和这个故事的寓意是:仔细检查你的清单文件您的许可,实际上说的READ_LOGS并不仅仅是READ_LOG
And the moral of the story is: double check that your permission in your manifest file actually says READ_LOGS and not just READ_LOG.
这篇关于机器人无法从应用程序中运行logcat的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!