Git Product home page Git Product logo

androidcrashhelper's Introduction

AndroidCrashHelper

Android Crash Helper。安卓APP自定义异常处理器,Release状态下意外奔溃提示更加友好(代替系统默认的那个讨厌的对话框),不影响Debug模式下LogCat的打印。

************************************************************************
**                              _oo0oo_                               **
**                             o8888888o                              **
**                             88" . "88                              **
**                             (| -_- |)                              **
**                             0\  =  /0                              **
**                           ___/'---'\___                            **
**                        .' \\\|     |// '.                          **
**                       / \\\|||  :  |||// \\                        **
**                      / _ ||||| -:- |||||- \\                       **
**                      | |  \\\\  -  /// |   |                       **
**                      | \_|  ''\---/''  |_/ |                       **
**                      \  .-\__  '-'  __/-.  /                       **
**                    ___'. .'  /--.--\  '. .'___                     **
**                 ."" '<  '.___\_<|>_/___.' >'  "".                  **
**                | | : '-  \'.;'\ _ /';.'/ - ' : | |                 **
**                \  \ '_.   \_ __\ /__ _/   .-' /  /                 **
**            ====='-.____'.___ \_____/___.-'____.-'=====             **
**                              '=---='                               **
************************************************************************

How to use

###下载AndroidCrashHelper,复制其中的“CrashHelper”到新项目作为依赖项:

dependencies {
    compile project(':CrashHelper')
}

最简单暴力的使用方法只需在AndroidManifest.xml中加入两句代码:

<application
   android:name="cn.qqtheme.framework.AppContext"
   ...>
      <activity android:name="cn.qqtheme.framework.activity.CrashActivity" />
      ...
</application>

下面是更灵活的应用。。。

分别建立一个Application子类及Activity子类,并在AndroidManifest.xml中声明:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application
   android:name=".DemoApp"
   ...>
      ...
      <activity
          android:name=".MyCrashActivity"
          android:exported="false">
            <intent-filter>
              <action android:name="liyujiang.intent.action.CRASH_ERROR" />
              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
      </activity>
      ...
</application>

注:AppContext类负责初始化设置自定义的奔溃报告页,CrashActivity为默认的奔溃报告页。 如果未在Application的onCreate方法里调用“AppContext.initialize()”,自定义异常处理器将不会生效。 如果没有调用“AppContext.initialize()”或CrashHelper.setCrashActivityClass()”设置Activity, 或者没有在AndroidManifest.xml中声明CrashActivity或含有action为“liyujiang.intent.action.CRASH_ERROR”的Activity, 那么将在SD卡根目录下生成crash.log文件(前提是要有WRITE_EXTERNAL_STORAGE权限)。
法一、可以继承自任何Application及Activity,然后调用AppContext.initialize()初始化:

public class DemoApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        AppContext.initialize(this, MyCrashActivity.class);
    }

}
public class MyCrashActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_crash);
        String stackTrace = CrashHelper.getStackTraceFromIntent(getIntent());
        String deviceInfo = CrashHelper.getDeviceInfo();
        ...
    }

}

法二、可以直接继承自AppContext及CrashActivity:

public class DemoApp extends AppContext {

    @Override
    public void onCreate() {
        super.onCreate();
        //initialize other you want
    }

}
public class MyCrashActivity extends CrashActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_crash);
        TextView tv = (TextView)findViewById(R.id.stacktrace);
        tv.setText(stackTrace);
        ...
    }

}

Screenshots

效果图
效果图
LogCat

Thanks

此项目核心代码来源于下面这个开源项目,大家去pull来学习吧:
https://github.com/Ereza/CustomActivityOnCrash

Contacts

Tencent QQ: 1032694760

androidcrashhelper's People

Contributors

liyujiang-gzu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.