package com.sinyee.babybus.listeners;public interface UncaughtExceptionListener{    void uncaughtException(String message, String stackTrace);}
package com.sinyee.babybus.talk2kiki;import java.lang.Thread.UncaughtExceptionHandler;import com.sinyee.babybus.listeners.UncaughtExceptionListener;import android.app.Application;import android.util.Log;import org.apache.commons.lang3.exception.ExceptionUtils;public class MyApplication extends Application{    private static MyApplication instance;        private final String TAG = "MyApplication";        private UncaughtExceptionListener uncaughtExceptionListener;        private UncaughtExceptionHandler defaultUncaughtExceptionHandler;            public MyApplication()    {        super();                instance = this;                defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();                // setup handler for uncaught exception         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {            @Override            public void uncaughtException(Thread thread, Throwable ex)            {                if(uncaughtExceptionListener != null)                {                    String message = ex.getMessage();                    String stackTrace = ExceptionUtils.getStackTrace(ex);                                        Log.e(TAG, "uncaughtException message " + message);                    Log.e(TAG, "uncaughtException stackTrace " + stackTrace);                                        uncaughtExceptionListener.uncaughtException(message, stackTrace);                }                defaultUncaughtExceptionHandler.uncaughtException(thread, ex);            }        });    }        public static void setUncaughtExceptionListener(UncaughtExceptionListener listener)    {        instance.uncaughtExceptionListener = listener;    }}
using UnityEngine;#if UNITY_ANDROIDpublic class UncaughtExceptionListener : AndroidJavaProxy{    public UncaughtExceptionListener() : base("com.sinyee.babybus.listeners.UncaughtExceptionListener") { }    public virtual void uncaughtException(string message, string stackTrace)    {        Debug.Log("UncaughtExceptionListener uncaughtException");    }}#endif
using UnityEngine;using System;#if UNITY_ANDROIDpublic class MyApplication{    public static void SetUncaughtExceptionListener(AndroidJavaProxy uncaughtExceptionListener)    {        if (Application.platform != RuntimePlatform.Android)            return;        new AndroidJavaClass("com.sinyee.babybus.talk2kiki.MyApplication").CallStatic("setUncaughtExceptionListener", uncaughtExceptionListener);    }}#endif

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)TextView、EditText显示表
  2. 搭建Android开发环境与开发工具选择
  3. Unity3d调用android中的方法
  4. 如果你想用对话框代替一个activity的话,可
  5. android EditText控件自动获取焦点弹出键
  6. Android(安卓)adb 常用技巧
  7. android——彻底关闭——应用程序
  8. 离线安装 Android(安卓)4.0 SDK
  9. Android游戏引擎选择
  10. Android总结篇系列:Android(安卓)权限