Unity Android(安卓)崩溃 处理
16lz
2021-01-26
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
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer