是否可以监听日志条目? 即附加日志条目时是否有广播 Intent ?
最佳答案
没有 Intent 。
使用下面的代码:
try
{
Process mLogcatProc = null;
BufferedReader reader = null;
mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));
String line;
final StringBuilder log = new StringBuilder();
String separator = System.getProperty("line.separator");
while ((line = reader.readLine()) != null)
{
log.append(line);
log.append(separator);
}
String w = log.toString();
Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
您将需要它的许可:
android.permission.READ_LOGS
关于Android 监听/检测日志条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3543846/