![](/img/trans.png)
[英]How to read the STORED logs from an attached device in Android Studio
[英]Read android device logs from my android application
我想獲取整個設備的日志,logcat顯示設備中運行的進程的方式。 我想從我的Android應用程序中捕獲它。
您的應用需要使用權限android.permission.READ_LOGS 。 (不確定這是否適用於無根設備)。
並且您需要在運行時向您的應用授予權限,以便通過以下方式訪問此權限:
adb shell pm grant <pkg> android.permission.READ_LOGS
(或)以編程方式:
Runtime.getRuntime().exec("pm grant <pkg> android.permission.READ_LOGS");
然后,您將能夠使用logcat的shell命令獲取系統日志。 例如,要將logcat轉儲作為設備中的txt文件:
Runtime.getRuntime().exec("logcat -d -f" + " /sdcard/Logcat_file.txt");
將獲取日志保存在Android設備的txt文件中,使用該文件可以進行進一步的驗證。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.