Android无法从应用程序运行logcat
因此,我正在编写一个分析器,它需要能够在分析会话期间记录异常。我的计划是使用logcat转储到SD卡或内部存储器上的文件,然后在分析会话完成时,压缩文件并将其发送到服务器。我在我的清单中添加了Android无法从应用程序运行logcat,android,logging,logcat,android-logcat,Android,Logging,Logcat,Android Logcat,因此,我正在编写一个分析器,它需要能够在分析会话期间记录异常。我的计划是使用logcat转储到SD卡或内部存储器上的文件,然后在分析会话完成时,压缩文件并将其发送到服务器。我在我的清单中添加了android.permission.READ_日志,我的代码如下: public void startLoggingExceptions() { String filename = null; String directory = null; String fullPath = n
android.permission.READ_日志
,我的代码如下:
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());
}
}
我原以为将清单权限添加到我的应用程序中会允许我这样做?这个故事的寓意是:仔细检查清单文件中的权限是否实际上是“读取日志”,而不仅仅是“读取日志”
这个故事的寓意是:仔细检查您的清单文件中的权限是否实际上是“读取日志”,而不仅仅是“读取日志”
以防有人遇到与我相同的问题:当试图从单元测试中读取logcat时,需要将权限添加到被测试的应用程序中,而不是测试项目中。仅将权限添加到测试项目仍会导致权限错误。以防有人遇到与我相同的问题:当试图从单元测试中读取logcat时,需要将权限添加到被测试的应用程序,而不是测试项目。仅将权限添加到测试项目仍将给出权限错误。这很奇怪,您的
运行时.getRuntime().exec(“…”)部件在我的设备上工作。这很奇怪,您的运行时.getRuntime().exec(“…”
部件在我的设备上工作。
Unable to open log device '/dev/log/main': Permission denied