├── .DS_Store
├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── sharejoys
│ │ └── crashhandlerlib
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── sharejoys
│ │ │ └── crashhandlerlib
│ │ │ ├── IApplication.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── sharejoys
│ └── crashhandlerlib
│ └── ExampleUnitTest.java
├── build.gradle
├── crashlib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── sharejoys
│ │ └── crashlib
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── sharejoys
│ │ │ └── crashlib
│ │ │ ├── CrashManager.java
│ │ │ ├── ui
│ │ │ ├── ExceptionCaughtAdapter.java
│ │ │ └── ShowExceptionActivity.java
│ │ │ └── util
│ │ │ ├── CrashFileHelper.java
│ │ │ ├── CrashFileProvider.java
│ │ │ └── CrashHelper.java
│ └── res
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── crash_lib_activity_show_exception.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_back_crash_lib_activity.png
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ └── ic_share_crash_lib_activity.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── provider_paths.xml
│ └── test
│ └── java
│ └── com
│ └── sharejoys
│ └── crashlib
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 | .idea/
16 |
17 | # Gradle files
18 | .gradle/
19 | build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # Intellij
37 | *.iml
38 | .idea/workspace.xml
39 | .idea/tasks.xml
40 | .idea/gradle.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | CrashHandlerLib
2 | ======
3 | 一个基于UncaughtExceptionHandler实现的Android奔溃日志捕获依赖库,使用该库可以显性的将奔溃日志展示出来,有助于开发以及测试人员在工作中及时定位奔溃问题.同时支持将奔溃日志分享到微信、QQ等第三方。
4 |
5 | 使用手册
6 | ======
7 |
8 | step 1.在根目录 build.gradle 上添加配置
9 | --------
10 | allprojects {
11 | repositories {
12 | ...
13 | maven { url 'https://jitpack.io' }
14 | }
15 | }
16 | step 2.在当前module的build.gradle添加如下依赖
17 | --------
18 | dependencies {
19 | implementation 'com.github.tuikes:CrashHandler:v2.1'
20 | }
21 |
22 | step 3.在Application中完成初始化
23 | --------
24 | @Override
25 | public void onCreate() {
26 | super.onCreate();
27 | CrashManager.getInstance().init(this, BuildConfig.DEBUG);
28 | }
29 |
30 | 效果演示
31 | ======
32 | step 1.测试代码源码
33 | --------
34 | 1>>>奔溃日志文件分享到QQ、微信等第三方:
35 |
36 | CrashManager.getInstance().shareCrashFile(MainActivity.this);
37 |
38 | 2>>>类型为TextView的result控件没有findViewById导致奔溃
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_main);
44 | test = findViewById(R.id.test);
45 |
46 | test.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | Log.d("cdx", test2.getText().toString());
50 | }
51 | });
52 |
53 | findViewById(R.id.share_crash_file).setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | //将奔溃信息分享到第三方
57 | CrashManager.getInstance().shareCrashFile(MainActivity.this);
58 | }
59 | });
60 | }
61 |
62 |
63 | step 2.运行查看效果
64 | --------
65 | 
66 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.sharejoys.crashhandlerlib"
7 | minSdkVersion 15
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | // implementation project(':crashlib')
29 |
30 | //奔溃日志捕获显示
31 | api "com.github.tuikes:CrashHandler:v2.3.1"
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/sharejoys/crashhandlerlib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashhandlerlib;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.sharejoys.crashhandlerlib", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sharejoys/crashhandlerlib/IApplication.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashhandlerlib;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.sharejoys.crashlib.CrashManager;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * 应用Application
15 | * Created by chendx on 2017/5/18.
16 | */
17 |
18 | public class IApplication extends Application {
19 | /**
20 | * 应用上下文
21 | */
22 | private static IApplication gInstance;
23 |
24 | /**
25 | * 获取应用上下文
26 | *
27 | * @return 应用上下文
28 | */
29 | public static IApplication getInstance() {
30 | return gInstance;
31 | }
32 |
33 |
34 | @Override
35 | public void onCreate() {
36 | super.onCreate();
37 | if (gInstance != null) {
38 | gInstance = this;
39 | return;
40 | }
41 | gInstance = this;
42 | CrashManager.getInstance().init(this, BuildConfig.DEBUG);
43 | }
44 |
45 | @Override
46 | protected void attachBaseContext(Context base) {
47 | super.attachBaseContext(base);
48 | }
49 |
50 | @Retention(RetentionPolicy.RUNTIME)
51 | @Target(ElementType.FIELD)
52 | public @interface Manager {
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sharejoys/crashhandlerlib/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashhandlerlib;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.sharejoys.crashlib.CrashManager;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 | private Button test;
13 | private Button test2;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 | test = findViewById(R.id.test);
20 |
21 | test.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View v) {
24 | Log.d("cdx", test2.getText().toString());
25 | }
26 | });
27 |
28 | findViewById(R.id.share_crash_file).setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | //将奔溃信息分享到第三方
32 | CrashManager.getInstance().shareCrashFile(MainActivity.this);
33 | }
34 | });
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CrashHandlerLib
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/sharejoys/crashhandlerlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashhandlerlib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.0'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | maven{url 'https://jitpack.io'}
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/crashlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/crashlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation 'com.android.support:support-v4:27.1.1'
30 | }
31 |
--------------------------------------------------------------------------------
/crashlib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/crashlib/src/androidTest/java/com/sharejoys/crashlib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.sharejoys.crashlib", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/crashlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
22 |
28 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/crashlib/src/main/java/com/sharejoys/crashlib/CrashManager.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 |
6 | import com.sharejoys.crashlib.ui.ExceptionCaughtAdapter;
7 | import com.sharejoys.crashlib.util.CrashHelper;
8 |
9 | /**
10 | * Created by chendx on 2018/5/2
11 | *
12 | * @since 1.0
13 | */
14 |
15 | public class CrashManager {
16 | private static final CrashManager gInstance = new CrashManager();
17 | private Application application;
18 | private boolean isDebug = true;//是否是debug模式
19 |
20 | public static CrashManager getInstance() {
21 | return gInstance;
22 | }
23 |
24 | public Application getApplication() {
25 | return application;
26 | }
27 |
28 | public boolean isDebug() {
29 | return isDebug;
30 | }
31 |
32 | private CrashManager() {
33 | }
34 |
35 | public void init(Application application, boolean isDebug) {
36 | this.application = application;
37 | this.isDebug = isDebug;
38 | CrashHelper.init();
39 | Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
40 | ExceptionCaughtAdapter exceptionCaughtAdapter = new ExceptionCaughtAdapter(handler);
41 | Thread.setDefaultUncaughtExceptionHandler(exceptionCaughtAdapter);
42 | }
43 |
44 | /**
45 | * 调用该方法可以将奔溃信息文件分享到第三方,如微信等
46 | *
47 | * @param activity 调用分享的activity
48 | */
49 | public void shareCrashFile(Activity activity) {
50 | if (application == null) {
51 | throw new IllegalStateException("CrashManager尚未被初始化,请先调用init完成初始化!!!!");
52 | }
53 | CrashHelper.shareCrashFile(activity);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/crashlib/src/main/java/com/sharejoys/crashlib/ui/ExceptionCaughtAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib.ui;
2 |
3 | import com.sharejoys.crashlib.CrashManager;
4 | import com.sharejoys.crashlib.util.CrashHelper;
5 |
6 | import java.lang.Thread.UncaughtExceptionHandler;
7 |
8 |
9 | public class ExceptionCaughtAdapter implements UncaughtExceptionHandler {
10 | private UncaughtExceptionHandler uncaughtExceptionHandler;
11 |
12 | public ExceptionCaughtAdapter(UncaughtExceptionHandler uncaughtExceptionHandler) {
13 | this.uncaughtExceptionHandler = uncaughtExceptionHandler;
14 | }
15 |
16 |
17 | @Override
18 | public void uncaughtException(Thread thread, Throwable ex) {
19 | String crashInfo = CrashHelper.buildCrashInfo(ex);
20 | CrashHelper.saveCrashLogToLocal(crashInfo);
21 | if (CrashManager.getInstance().isDebug()) {//debug模式下才显性的展示崩溃信息
22 | ShowExceptionActivity.showException(crashInfo);
23 | }
24 | if (uncaughtExceptionHandler != null) {
25 | uncaughtExceptionHandler.uncaughtException(thread, ex);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/crashlib/src/main/java/com/sharejoys/crashlib/ui/ShowExceptionActivity.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib.ui;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import com.sharejoys.crashlib.CrashManager;
11 | import com.sharejoys.crashlib.R;
12 |
13 |
14 | /**
15 | * 崩溃日志显示界面
16 | *
17 | * @author chendx
18 | */
19 | public class ShowExceptionActivity extends Activity {
20 | private static final String KEY_CRASH_INFO = "key_crash_info";
21 | private TextView exceptionView;
22 |
23 | public static void showException(String crashInfo) {
24 | Application applicationContext = CrashManager.getInstance().getApplication();
25 | if (applicationContext != null) {
26 | Intent intent = new Intent(applicationContext, ShowExceptionActivity.class);
27 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
28 | intent.putExtra(KEY_CRASH_INFO, crashInfo);
29 | applicationContext.startActivity(intent);
30 | }
31 | }
32 |
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.crash_lib_activity_show_exception);
38 | setListener();
39 | int exceptionId = getResources().getIdentifier("crash_lib_activity_show_exception_view", "id", getPackageName());
40 | exceptionView = findViewById(exceptionId);
41 | handlerIntent(getIntent(), false);
42 | }
43 |
44 | private void setListener() {
45 | int backBtnId = getResources().getIdentifier("crash_lib_activity_back_btn", "id", getPackageName());
46 | int shareBtnId = getResources().getIdentifier("crash_lib_activity_share_btn", "id", getPackageName());
47 | findViewById(backBtnId).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | finish();
51 | }
52 | });
53 | findViewById(shareBtnId).setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | CrashManager.getInstance().shareCrashFile(ShowExceptionActivity.this);
57 | }
58 | });
59 | }
60 |
61 | @Override
62 | protected void onNewIntent(Intent intent) {
63 | super.onNewIntent(intent);
64 | handlerIntent(intent, true);
65 | }
66 |
67 | private void handlerIntent(Intent intent, boolean isNew) {
68 | String msg = intent.getStringExtra(KEY_CRASH_INFO);
69 | if (msg != null) {
70 | if (isNew)
71 | exceptionView.append("\n\n\n\n\n\n");
72 | exceptionView.append(msg);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/crashlib/src/main/java/com/sharejoys/crashlib/util/CrashFileHelper.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.net.Uri;
6 | import android.os.Build;
7 | import android.os.Environment;
8 | import android.support.v4.content.FileProvider;
9 | import android.util.Log;
10 |
11 | import java.io.BufferedInputStream;
12 | import java.io.BufferedOutputStream;
13 | import java.io.File;
14 | import java.io.FileInputStream;
15 | import java.io.FileNotFoundException;
16 | import java.io.FileOutputStream;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.text.DecimalFormat;
20 | import java.text.SimpleDateFormat;
21 | import java.util.Date;
22 | import java.util.zip.ZipEntry;
23 | import java.util.zip.ZipOutputStream;
24 |
25 | public class CrashFileHelper {
26 | private final static String TAG = "CrashFileHelper";
27 | public static final String FILE_PROVIDER_NAME = "fileprovider";
28 |
29 | /**
30 | * Get sdcard path
31 | *
32 | * @return the path
33 | */
34 | public static String getSDPath() {
35 | File sdDir = null;
36 | boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
37 | if (sdCardExist) {
38 | sdDir = Environment.getExternalStorageDirectory();
39 | }
40 | return sdDir.toString();
41 | }
42 |
43 |
44 |
45 |
46 | /**
47 | * Get brandArray random file name according to current date
48 | *
49 | * @return brandArray random file name
50 | */
51 | public static String getRandomFileName() {
52 | Date todate = new Date();
53 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
54 | return sdf.format(todate);
55 | }
56 |
57 |
58 | /**
59 | * Create dir recursively
60 | *
61 | * @param path path name
62 | */
63 | public static void createDirs(String path) {
64 | File file = new File(path);
65 | if (!file.exists()) {
66 | file.mkdirs();
67 | }
68 | }
69 |
70 |
71 | /**
72 | * 拍照路径 6.19
73 | */
74 |
75 | private static String FILE_NAME = "userIcon.jpg";
76 | public static String PATH_PHOTOGRAPH = "/smt/";
77 |
78 | private static boolean isExternalStorageWritable() {
79 | String state = Environment.getExternalStorageState();
80 | return Environment.MEDIA_MOUNTED.equals(state);
81 | }
82 |
83 |
84 | /**
85 | * 保存图片
86 | *
87 | * @param bitmap
88 | * @param filePath
89 | */
90 | public static void saveBitmap(Bitmap bitmap, String filePath) {
91 | FileOutputStream bos = null;
92 | File file = new File(filePath);
93 | if (!file.getParentFile().exists()) {
94 | file.getParentFile().mkdirs();
95 | }
96 | try {
97 | bos = new FileOutputStream(file);
98 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
99 | } catch (FileNotFoundException e) {
100 | e.printStackTrace();
101 | } finally {
102 | try {
103 | bos.flush();
104 | bos.close();
105 | } catch (IOException e) {
106 | e.printStackTrace();
107 | }
108 | }
109 | }
110 |
111 |
112 | public static File getDCIMFile(String filePath, String imageName) {
113 | if (Environment.getExternalStorageState().equals(
114 | Environment.MEDIA_MOUNTED)) { // 文件可用
115 | File dirs = new File(Environment.getExternalStorageDirectory(),
116 | "DCIM" + filePath);
117 | if (!dirs.exists())
118 | dirs.mkdirs();
119 |
120 | File file = new File(Environment.getExternalStorageDirectory(),
121 | "DCIM" + filePath + imageName);
122 | if (!file.exists()) {
123 | try {
124 | //在指定的文件夹中创建文件
125 | file.createNewFile();
126 | } catch (Exception e) {
127 | }
128 | }
129 | return file;
130 | } else {
131 | return null;
132 | }
133 |
134 | }
135 |
136 |
137 | public static File saveBitmap2(Bitmap bitmap, String fileName, File baseFile) {
138 | FileOutputStream bos = null;
139 | File imgFile = new File(baseFile, "/" + fileName);
140 | try {
141 | bos = new FileOutputStream(imgFile);
142 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
143 | } catch (FileNotFoundException e) {
144 | e.printStackTrace();
145 | } finally {
146 | try {
147 | bos.flush();
148 | bos.close();
149 | } catch (IOException e) {
150 | e.printStackTrace();
151 | }
152 | }
153 | return imgFile;
154 | }
155 |
156 | public static File getBaseFile(String filePath) {
157 | if (Environment.getExternalStorageState().equals(
158 | Environment.MEDIA_MOUNTED)) { // 文件可用
159 | File f = new File(Environment.getExternalStorageDirectory(),
160 | filePath);
161 | if (!f.exists())
162 | f.mkdirs();
163 | return f;
164 | } else {
165 | return null;
166 | }
167 | }
168 |
169 | public static String getFileName() {
170 | String fileName = FILE_NAME;
171 | return fileName;
172 | }
173 |
174 | /**
175 | * 由指定的路径和文件名创建文件
176 | */
177 | public static File createFile(String path, String name) throws IOException {
178 | File folder = new File(path);
179 | if (!folder.exists()) {
180 | folder.mkdirs();
181 | }
182 | File file = new File(path + name);
183 | if (!file.exists()) {
184 | file.createNewFile();
185 | }
186 | return file;
187 | }
188 |
189 | /**
190 | * 获取文件对应的URI
191 | * @param context
192 | * @param file
193 | * @return
194 | */
195 | public static Uri getUri(Context context, File file) {
196 | Uri uri;
197 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
198 | //data是file类型,忘了复制过来
199 | uri = FileProvider.getUriForFile(context, context.getPackageName() + "."+FILE_PROVIDER_NAME,
200 | file);
201 | } else {
202 | uri = Uri.fromFile(file);
203 | }
204 | return uri;
205 | }
206 |
207 |
208 | /**
209 | * 压缩文件
210 | *
211 | * @param fs 需要压缩的文件
212 | * @param zipFilePath 被压缩后存放的路径
213 | * @return 成功返回 true,否则 false
214 | */
215 | public static boolean zipFiles(File fs[], String zipFilePath) {
216 | if (fs == null) {
217 | throw new NullPointerException("fs == null");
218 | }
219 | boolean result = false;
220 | ZipOutputStream zos = null;
221 | try {
222 | zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFilePath)));
223 | for (File file : fs) {
224 | if (file == null || !file.exists() || file.getName().toLowerCase().endsWith("zip")) {
225 | continue;
226 | }
227 | if (file.isDirectory()) {
228 | recursionZip(zos, file, file.getName() + File.separator);
229 | } else {
230 | recursionZip(zos, file, "");
231 | }
232 | }
233 | result = true;
234 | zos.flush();
235 | } catch (Exception e) {
236 | e.printStackTrace();
237 | Log.e(TAG, "zip file failed err: " + e.getMessage());
238 | } finally {
239 | try {
240 | if (zos != null) {
241 | zos.closeEntry();
242 | zos.close();
243 | }
244 | } catch (IOException e1) {
245 | e1.printStackTrace();
246 | }
247 | }
248 | return result;
249 | }
250 |
251 |
252 | private static void recursionZip(ZipOutputStream zipOut, File file, String baseDir) throws Exception {
253 | if (file.isDirectory()) {
254 | Log.i(TAG, "the file is dir name -->>" + file.getName() + " the baseDir-->>>" + baseDir);
255 | File[] files = file.listFiles();
256 | for (File fileSec : files) {
257 | if (fileSec == null) {
258 | continue;
259 | }
260 | if (fileSec.isDirectory()) {
261 | baseDir = file.getName() + File.separator + fileSec.getName() + File.separator;
262 | Log.i(TAG, "basDir111-->>" + baseDir);
263 | recursionZip(zipOut, fileSec, baseDir);
264 | } else {
265 | Log.i(TAG, "basDir222-->>" + baseDir);
266 | recursionZip(zipOut, fileSec, baseDir);
267 | }
268 | }
269 | } else {
270 | Log.i(TAG, "the file name is -->>" + file.getName() + " the base dir -->>" + baseDir);
271 | byte[] buf = new byte[2048];
272 | InputStream input = new BufferedInputStream(new FileInputStream(file));
273 | zipOut.putNextEntry(new ZipEntry(baseDir + file.getName()));
274 | int len;
275 | while ((len = input.read(buf)) != -1) {
276 | zipOut.write(buf, 0, len);
277 | }
278 | input.close();
279 | }
280 | }
281 |
282 | /**
283 | * 文件大小(长度转化文字展示)
284 | *
285 | * @param var0 长度
286 | */
287 | public static String getDataSize(long var0) {
288 | DecimalFormat var2 = new DecimalFormat("###.00");
289 | return var0 < 1024L ? var0 + "bytes"
290 | : (var0 < 1048576L ? var2.format((double) ((float) var0 / 1024.0F)) + "KB"
291 | : (var0 < 1073741824L ? var2.format(
292 | (double) ((float) var0 / 1024.0F / 1024.0F)) + "MB"
293 | : (var0 < 0L ? var2.format(
294 | (double) ((float) var0 / 1024.0F / 1024.0F / 1024.0F))
295 | + "GB" : "error")));
296 | }
297 | }
298 |
--------------------------------------------------------------------------------
/crashlib/src/main/java/com/sharejoys/crashlib/util/CrashFileProvider.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib.util;
2 |
3 | import android.support.v4.content.FileProvider;
4 |
5 | /**
6 | * Created by chendaixi947 on 2018/6/21
7 | *
8 | * @since 1.0
9 | */
10 | public class CrashFileProvider extends FileProvider{
11 | }
12 |
--------------------------------------------------------------------------------
/crashlib/src/main/java/com/sharejoys/crashlib/util/CrashHelper.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib.util;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.content.pm.PackageInfo;
7 | import android.content.pm.PackageManager;
8 | import android.net.Uri;
9 | import android.os.Build;
10 | import android.os.Environment;
11 | import android.util.Log;
12 | import android.widget.Toast;
13 |
14 | import com.sharejoys.crashlib.CrashManager;
15 |
16 | import java.io.BufferedWriter;
17 | import java.io.File;
18 | import java.io.FileWriter;
19 | import java.io.IOException;
20 | import java.io.PrintWriter;
21 | import java.io.StringWriter;
22 | import java.text.Format;
23 | import java.text.SimpleDateFormat;
24 | import java.util.Date;
25 | import java.util.concurrent.Callable;
26 | import java.util.concurrent.ExecutionException;
27 | import java.util.concurrent.Executors;
28 | import java.util.concurrent.Future;
29 |
30 | /**
31 | * 异常捕获工具类 by zc 2018年05月07日15:24:15
32 | */
33 | public final class CrashHelper {
34 | private static String defaultDir;
35 | private static String versionName;
36 | private static int versionCode;
37 |
38 | private static final String FILE_SEP = System.getProperty("file.separator");
39 | @SuppressLint("SimpleDateFormat")
40 | private static final Format FORMAT =
41 | new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
42 |
43 |
44 | public static void init() {
45 | defaultDir = getDefaultCrashDir();
46 | }
47 |
48 | private CrashHelper() {
49 | throw new UnsupportedOperationException("u can't instantiate me...");
50 | }
51 |
52 |
53 | static {
54 | try {
55 | PackageInfo pi = CrashManager.getInstance().getApplication()
56 | .getPackageManager()
57 | .getPackageInfo(CrashManager.getInstance().getApplication().getPackageName(), 0);
58 | if (pi != null) {
59 | versionName = pi.versionName;
60 | versionCode = pi.versionCode;
61 | }
62 | } catch (PackageManager.NameNotFoundException e) {
63 | e.printStackTrace();
64 | }
65 | }
66 |
67 |
68 | /**
69 | * 拼接奔溃信息
70 | */
71 | public static String buildCrashInfo(Throwable e) {
72 | final StringBuilder sb = new StringBuilder();
73 | final String time = FORMAT.format(new Date(System.currentTimeMillis()));
74 | final String head = "************* Log Head ****************"
75 | + "\nTime Of Crash : "
76 | + time
77 | + "\nDevice Manufacturer: "
78 | + Build.MANUFACTURER
79 | + "\nDevice Model : "
80 | + Build.MODEL
81 | + "\nAndroid Version : "
82 | + Build.VERSION.RELEASE
83 | + "\nAndroid SDK : "
84 | + Build.VERSION.SDK_INT
85 | + "\nApp VersionName : "
86 | + versionName
87 | + "\nApp VersionCode : "
88 | + versionCode
89 | + "\n************* Log Head ****************\n\n";
90 | sb.append(head);
91 | StringWriter sw = new StringWriter();
92 | PrintWriter pw = new PrintWriter(sw);
93 | e.printStackTrace(pw);
94 | Throwable cause = e.getCause();
95 | while (cause != null) {
96 | cause.printStackTrace(pw);
97 | cause = cause.getCause();
98 | }
99 | pw.flush();
100 | sb.append(sw.toString());
101 | return sb.toString();
102 | }
103 |
104 | /**
105 | * 将奔溃信息存储到本地
106 | */
107 | public static void saveCrashLogToLocal(String crashInfo) {
108 | final String time = FORMAT.format(new Date(System.currentTimeMillis()));
109 | final String fullPath = defaultDir + time + ".txt";
110 | if (createOrExistsFile(fullPath)) {
111 | input2File(crashInfo, fullPath);
112 | } else {
113 | Log.e("CrashHelper", "create " + fullPath + " failed!");
114 | }
115 | }
116 |
117 | /**
118 | * get default crash log dir
119 | *
120 | * @return dir
121 | */
122 | private static String getDefaultCrashDir() {
123 | if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
124 | && CrashManager.getInstance().getApplication().getExternalCacheDir() != null) {
125 | return CrashManager.getInstance().getApplication().getExternalCacheDir()
126 | + FILE_SEP
127 | + "crash_log"
128 | + FILE_SEP;
129 | } else {
130 | return CrashManager.getInstance().getApplication().getCacheDir()
131 | + FILE_SEP
132 | + "crash_log"
133 | + FILE_SEP;
134 | }
135 | }
136 |
137 | private static void input2File(final String input, final String filePath) {
138 | Future submit =
139 | Executors.newSingleThreadExecutor().submit(new Callable() {
140 | @Override
141 | public Boolean call() throws Exception {
142 | BufferedWriter bw = null;
143 | try {
144 | bw = new BufferedWriter(new FileWriter(filePath, true));
145 | bw.write(input);
146 | onClearFile();
147 | return true;
148 | } catch (IOException e) {
149 | e.printStackTrace();
150 | return false;
151 | } finally {
152 | try {
153 | if (bw != null) {
154 | bw.close();
155 | }
156 | } catch (IOException e) {
157 | e.printStackTrace();
158 | }
159 | }
160 | }
161 | });
162 | try {
163 | if (submit.get()) return;
164 | } catch (InterruptedException e) {
165 | e.printStackTrace();
166 | } catch (ExecutionException e) {
167 | e.printStackTrace();
168 | }
169 | Log.e("CrashHelper", "write crash info to " + filePath + " failed!");
170 | }
171 |
172 | private static boolean createOrExistsFile(final String filePath) {
173 | File file = new File(filePath);
174 | if (file.exists()) return file.isFile();
175 | if (!createOrExistsDir(file.getParentFile())) return false;
176 | try {
177 | return file.createNewFile();
178 | } catch (IOException e) {
179 | e.printStackTrace();
180 | return false;
181 | }
182 | }
183 |
184 | private static boolean createOrExistsDir(final File file) {
185 | return file != null && (file.exists() ? file.isDirectory() : file.mkdirs());
186 | }
187 |
188 | /**
189 | * 删除超过2天的文件,防止过多
190 | */
191 | private static void onClearFile() {
192 | if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
193 | File file = new File(getDefaultCrashDir());
194 | if (file.exists()) {
195 | if (file.listFiles().length > 3) {
196 | int index = 0;
197 | for (File temp : file.listFiles()) {
198 | long time = System.currentTimeMillis() - temp.lastModified();
199 | if (time / 1000 > 3600 * 24 * 2) {
200 | temp.delete();
201 | index++;
202 | }
203 | if (index >= file.listFiles().length - 3) break;
204 | }
205 | }
206 | }
207 | }
208 | }
209 |
210 | //******************************************分享相关开始**********************************************
211 | private static final String LOG_ZIP_FILE_PATH = CrashHelper.getDefaultCrashDir() + File.separator + "crash_log.zip";
212 |
213 | public static void shareCrashFile(Activity activity) {
214 | File logPath = new File(CrashHelper.getDefaultCrashDir());
215 | if (!logPath.exists() || logPath.listFiles() == null || logPath.listFiles().length == 0) {
216 | Toast.makeText(activity,"没有崩溃日志可以反馈",Toast.LENGTH_SHORT).show();
217 | return;
218 | }
219 | if (logPath.listFiles().length == 1) {//只有一个崩溃文件则直接打开
220 | Uri uri = CrashFileHelper.getUri(activity, logPath.listFiles()[0]);
221 | shareFile(activity, uri, "text/plain");
222 | } else {//多个文件的话,压缩之后发送压缩包
223 | CrashFileHelper.zipFiles(logPath.listFiles(), LOG_ZIP_FILE_PATH);
224 | Uri uri = CrashFileHelper.getUri(activity, new File(LOG_ZIP_FILE_PATH));
225 | shareFile(activity, uri, "application/zip");
226 | }
227 | }
228 |
229 |
230 | /**
231 | * 分享文件
232 | *
233 | * @param fileUri 文件uri
234 | * @param fileType 文件类型(具体文件类型可参见本类下方注释)
235 | */
236 | private static void shareFile(Activity activity, Uri fileUri, String fileType) {
237 | //表示要创建一个发送指定内容的隐式意图
238 | Intent intent = new Intent(Intent.ACTION_SEND);
239 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
240 | //读取权限
241 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
242 | //指定发送的内容
243 | intent.putExtra(Intent.EXTRA_STREAM, fileUri);
244 | //intent.putExtra(Intent.EXTRA_STREAM,uri);
245 | //指定发送内容的类型
246 | intent.setType(fileType);
247 | try {
248 | activity.startActivity(intent);
249 | } catch (Exception e) {
250 | e.printStackTrace();
251 | }
252 | }
253 | //******************************************分享相关结束**********************************************
254 |
255 | }
256 |
--------------------------------------------------------------------------------
/crashlib/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/crashlib/src/main/res/layout/crash_lib_activity_show_exception.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
24 |
25 |
34 |
35 |
36 |
37 |
38 |
41 |
42 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xhdpi/ic_back_crash_lib_activity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xhdpi/ic_back_crash_lib_activity.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xhdpi/ic_share_crash_lib_activity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xhdpi/ic_share_crash_lib_activity.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/crashlib/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/crashlib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #3F51B5
7 |
8 |
--------------------------------------------------------------------------------
/crashlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CrashLib
3 |
4 |
--------------------------------------------------------------------------------
/crashlib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/crashlib/src/main/res/xml/provider_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
10 |
13 |
14 |
17 |
18 |
21 |
24 |
--------------------------------------------------------------------------------
/crashlib/src/test/java/com/sharejoys/crashlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.sharejoys.crashlib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuikes/CrashHandler/e45cd1fae680f715844ab506ffb91a4aa8868fd8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 21 10:06:01 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file must *NOT* be checked into Version Control Systems,
2 | # as it contains information specific to your local configuration.
3 | #
4 | # Location of the SDK. This is only used by Gradle.
5 | # For customization when using a Version Control System, please read the
6 | # header note.
7 | #Thu Jun 21 10:05:17 CST 2018
8 | sdk.dir=/Users/chendaixi947/Library/Android/sdk
9 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':crashlib'
2 |
--------------------------------------------------------------------------------