Blame view

src/com/ectrip/cyt/exceptionsave/debug/SystemCrashLog.java 2.29 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
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
77
78
79
80
81
82
83
  package com.ectrip.cyt.exceptionsave.debug;
  
  import java.lang.Thread.UncaughtExceptionHandler;
  
  import com.ectrip.cyt.exceptionsave.info.ApplitionInfo;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.content.pm.ApplicationInfo;
  import android.content.pm.PackageManager;
  
  
  /**
   * 系统崩溃日志
   * @author Aiushtha
   */
  @SuppressLint("SimpleDateFormat")
  public class SystemCrashLog implements UncaughtExceptionHandler,Runnable{
  
  
  	/**单例*/
  	private static SystemCrashLog INSTANCE ;
  	/**上下文环境*/
  	private Context mContext;
  	/**错误*/
  	private Throwable ex;
  
  	/**初始化*/
  	public static SystemCrashLog init(Context context) {
  		return INSTANCE=(INSTANCE==null?new SystemCrashLog(context):INSTANCE);
  	}
  	/**构造方法*/
  	public SystemCrashLog(Context ctx) {
  		mContext = ctx;
  		Thread.setDefaultUncaughtExceptionHandler(this);
  	}
  	/**捕获异常并处理*/
  	@Override
  	public void uncaughtException(Thread thread, final Throwable ex) {
  		this.ex=ex;
  		LocalLogRunnable  localLogRunnable=new LocalLogRunnable(mContext,ex);
  
  
  		String subject="应用程序"+getApplicationName()+" "+"发生了一个崩溃";
  		StringBuffer sb=new StringBuffer();
  		sb.append("android-id:"+ApplitionInfo.getAndroidId(mContext)+"\n")
  				.append("android-code:"+ApplitionInfo.getVersionCode(mContext)+"\n")
  				.append("android-version:"+ApplitionInfo.getVersionName(mContext)+"\n");
  
  
  		localLogRunnable.run();
  
  //	    EmailRunnable emailRunnable=new EmailRunnable(mContext,ex); //发送错误到邮件
  //	    emailRunnable.setSubject(subject);
  //	    emailRunnable.setBody(sb.toString());
  //	    emailRunnable.setAttachment(localLogRunnable.getLog_file_path());
  //		new Thread(emailRunnable).start();
  	}
  
  	public String getApplicationName() {
  		PackageManager packageManager = null;
  		ApplicationInfo applicationInfo = null;
  		try {
  			packageManager = mContext.getApplicationContext().getPackageManager();
  			applicationInfo = packageManager.getApplicationInfo(mContext.getApplicationContext().getPackageName(), 0);
  		} catch (PackageManager.NameNotFoundException e) {
  			applicationInfo = null;
  		}
  		String applicationName =
  				(String) packageManager.getApplicationLabel(applicationInfo);
  		return applicationName;
  	}
  	@Override
  	public void run() {
  		// TODO Auto-generated method stub
  
  	}
  
  
  
  
  
  }