当前位置: 首页 > 工具软件 > ANR-WatchDog > 使用案例 >

使用anrwatchdog抓取错误日志

莘绍元
2023-12-01

github网址:https://github.com/SalomonBrys/ANR-WatchDog
buld.gradle 中引入implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'


public class WatchDogUtils {

    public static final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 1001;
    private static final String ADR_DUMP_PATH = "anrHprof";
    private static File mExternalReportPath;
    private static ANRWatchDog anrWatchDog;

    public static void startAnrWatch(Context context) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(
                    (Activity) context,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
        } else {
            initANRWatchDog(context);
 
 类似资料: