| | |
| | | package com.basic.security.utils; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.app.AlarmManager; |
| | | import android.app.PendingIntent; |
| | |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Build; |
| | | import android.os.Environment; |
| | | import android.os.Looper; |
| | | import android.os.SystemClock; |
| | | import android.util.Log; |
| | | import android.widget.Toast; |
| | | |
| | | import com.basic.security.activity.MainActivity_; |
| | | import com.basic.security.base.BaseApplication; |
| | | import com.facebook.common.file.FileUtils; |
| | | |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.xutils.common.util.FileUtil; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | |
| | | public class CrashHandler implements Thread.UncaughtExceptionHandler { |
| | | |
| | | public static String TAG = "MyCrash"; |
| | | // 系统默认的UncaughtException处理类 |
| | | private Thread.UncaughtExceptionHandler mDefaultHandler; |
| | | |
| | | private static com.basic.security.utils.CrashHandler instance = new com.basic.security.utils.CrashHandler(); |
| | | private Context mContext; |
| | | |
| | | // 用来存储设备信息和异常信息 |
| | | private Map<String, String> infos = new HashMap<String, String>(); |
| | | |
| | | // 用于格式化日期,作为日志文件名的一部分 |
| | | private static DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 系统默认的UncaughtException处理类 |
| | | private Thread.UncaughtExceptionHandler mDefaultHandler; |
| | | private Context mContext; |
| | | // 用来存储设备信息和异常信息 |
| | | private Map<String, String> infos = new HashMap<String, String>(); |
| | | |
| | | /** |
| | | * 保证只有一个CrashHandler实例 |
| | |
| | | */ |
| | | public static com.basic.security.utils.CrashHandler getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public static String getErrorContent() { |
| | | String time = formatter.format(new Date()); |
| | | String fileName = "crash-" + time + ".log"; |
| | | String content = ""; |
| | | try { |
| | | String path = getGlobalpath(); |
| | | File dir = new File(path); |
| | | if (!dir.exists()) |
| | | dir.mkdirs(); |
| | | File file = new File(path + fileName); |
| | | if (file.exists()) { |
| | | content = FileCopyUtils.copyToString(new FileReader(file)); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public static String getGlobalpath() { |
| | | // return BaseApplication.getApplication().getFilesDir().getAbsolutePath(); |
| | | // return Environment.getExternalStorageDirectory().getAbsolutePath() |
| | | // + File.separator + "crash" + File.separator; |
| | | return Environment.getExternalStorageDirectory().getAbsolutePath() |
| | | + File.separator + "crash" + File.separator; |
| | | } |
| | | |
| | | public static void setTag(String tag) { |
| | | TAG = tag; |
| | | } |
| | | |
| | | /** |
| | |
| | | fos.close(); |
| | | } |
| | | return fileName; |
| | | } |
| | | |
| | | |
| | | public static String getErrorContent() { |
| | | String time = formatter.format(new Date()); |
| | | String fileName = "crash-" + time + ".log"; |
| | | String content = ""; |
| | | try { |
| | | String path = getGlobalpath(); |
| | | File dir = new File(path); |
| | | if (!dir.exists()) |
| | | dir.mkdirs(); |
| | | File file = new File(path+fileName); |
| | | if (file.exists()) { |
| | | content = FileCopyUtils.copyToString(new FileReader(file)); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public static String getGlobalpath() { |
| | | return BaseApplication.getApplication().getFilesDir().getAbsolutePath(); |
| | | // return Environment.getExternalStorageDirectory().getAbsolutePath() |
| | | // + File.separator + "crash" + File.separator; |
| | | } |
| | | |
| | | public static void setTag(String tag) { |
| | | TAG = tag; |
| | | } |
| | | |
| | | /** |