admin
6 天以前 7f0825f8195a522ed7e8bcdb6347f3a719e06c74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.weikou.beibeivideo.util;
 
import android.content.Context;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
 
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.Thread.UncaughtExceptionHandler;
 
/**
 * 崩溃时写入日志工具类
 * @author pys
 *
 */
public class LeTVCrashHandler implements UncaughtExceptionHandler {
    public static final String TAG = CrashHandler.class.getSimpleName();
 
    private static LeTVCrashHandler instance;
    private Context context;
 
    private LeTVCrashHandler(Context context) {
        this.context = context;
        Thread.setDefaultUncaughtExceptionHandler(this);
    }
 
    public static synchronized LeTVCrashHandler getInstance(Context context) {
        if (instance == null) {
            instance = new LeTVCrashHandler(context);
        }
        return instance;
    }
 
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        handleException(ex);
    }
 
    private void handleException(Throwable ex) {
        if (ex == null) {
            return;
        }
        StringBuffer sb = new StringBuffer("Oh Madan player is crash !!!!!!!!!!!!! \n");
        Writer writer = new StringWriter();
        PrintWriter printWriter = new PrintWriter(writer);
        ex.printStackTrace(printWriter);
        Throwable cause = ex.getCause();
        while (cause != null) {
            cause.printStackTrace(printWriter);
            cause = cause.getCause();
        }
        String result = writer.toString();
        sb.append(result);
//        LeLog.ePringShenShou(TAG, sb.toString());
        Log.e(TAG, sb.toString());
        new Thread(new Runnable() {
            
            @Override
            public void run() {
                Looper.prepare();
                Toast.makeText(context, " oh player is crash", Toast.LENGTH_SHORT).show();
                Looper.loop();
                
            }
        }).start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
 
}