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);