Back to project page FrameLite.
The source code is released under:
GNU General Public License
If you think the Android project FrameLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.miku.framelite.services; /*from w w w .j a v a 2 s. c o m*/ import java.lang.Thread.UncaughtExceptionHandler; import java.lang.reflect.Field; import com.miku.framelite.utils.DimensionUtils; import com.miku.framelite.utils.Log; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; import android.os.Environment; /** * ????????????? * * @author xr.lee * */ public class CrashHandler implements UncaughtExceptionHandler { private static final String TAG = CrashHandler.class.getSimpleName(); private Context mContext; private UncaughtExceptionHandler mDefaultHandler; private static CrashHandler INSTANCE; private CrashHandler(Context context) { mContext = context; mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); } public static void Init(Context context) { if (INSTANCE == null) { INSTANCE = new CrashHandler(context); } } @Override public void uncaughtException(Thread thread, Throwable ex) { handleUncaughtException(thread, ex); // ???????????? if (mDefaultHandler != null) { mDefaultHandler.uncaughtException(thread, ex); } } private void handleUncaughtException(Thread thread, Throwable throwable) { // ??sd??????????????? if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { saveCrashInfoToFile(thread, throwable); } } /** * ????????????? * * @param thread * ex * @return */ private void saveCrashInfoToFile(Thread thread, Throwable ex) { Log.writeLog(thread, TAG, collectCrashDeviceInfo(), ex); } /** * ?????????????? */ public String collectCrashDeviceInfo() { StringBuilder sb = new StringBuilder(); try { PackageManager pm = mContext.getPackageManager(); PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_ACTIVITIES); if (pi != null) { sb.append("VersionName:") .append(pi.versionName == null ? "not set" : pi.versionName).append("\n\r"); sb.append("VersionCode:").append(pi.versionCode).append("\n\r"); } } catch (NameNotFoundException e) { Log.e(TAG, "Error while collect package info", e); } int[] screen=DimensionUtils.getDisplayScreenResolution(mContext); sb.append("ScreenInfo--Width:").append(screen[0]).append(" Height:").append(screen[1]).append("\n\r"); // ?????????????????.?Build?????????????????, // ??: ???????,????? ??????????????? Field[] fields = Build.class.getDeclaredFields(); for (Field field : fields) { try { field.setAccessible(true); sb.append(field.getName()).append(" : ").append(field.get(null).toString()) .append("\n\r"); } catch (Exception e) { Log.e(TAG, "Error while collect crash info", e); } } return sb.toString(); } }