Skip to content

Commit

Permalink
优化代码,添加回调处理
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Nov 8, 2017
1 parent 7494502 commit 8a36714
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 71 deletions.
47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Debug监听程序崩溃日志,直接页面展示崩溃日志列表,方便自
#### 2.在app目录下的build.gradle中添加依赖
``` gradle
dependencies {
      compile 'com.github.maning0303:MNCrashMonitor:V1.0.2'
      compile 'com.github.maning0303:MNCrashMonitor:V1.0.3'
}
```

Expand All @@ -36,30 +36,61 @@ Debug监听程序崩溃日志,直接页面展示崩溃日志列表,方便自

``` java

/**
* 初始化日志系统
* context : 上下文
* isDebug : 是不是Debug模式,true:崩溃后显示自定义崩溃页面 ;false:关闭应用,不跳转奔溃页面(默认)
*/
MCrashMonitor.init(this, true);
/**
* 初始化日志系统
* context : 上下文
* isDebug : 是不是Debug模式,true:崩溃后显示自定义崩溃页面 ;false:关闭应用,不跳转奔溃页面(默认)
* CrashCallBack : 回调执行
*/
MCrashMonitor.init(this, true, new CrashCallBack() {
@Override
public void onCrash(File file) {
//可以在这里重启应用
//可以在这里保存标识,下次再次进入把日志发送给服务器
Log.i(TAG, "CrashMonitor回调:" + file.getAbsolutePath());
}
});

```

### 2:文件的位置:
``` java

/Android/data/包名/cache/crashLogs/
或者
/data/data/包名/cache/crashLogs/

```


### 喜欢就Star一下吧!

### 注意:
当应用已启动就崩溃的无法打开页面,直接看通知或者去文件夹里面查看:/Android/data/包名/cache/crashLogs/
当应用已启动就崩溃的无法打开页面,直接看通知或者去文件夹里面查看:
/Android/data/包名/cache/crashLogs/
或者
/data/data/包名/cache/crashLogs/

## 感谢:
#### 内部使用了一些三方库文件:
##### [StatusBarUtil](https://github.com/laobie/StatusBarUtil)
##### [NotifyUtil](https://github.com/wenmingvs/NotifyUtil)


## 推荐:
Name | Describe |
--- | --- |
[GankMM](https://github.com/maning0303/GankMM) | (Material Design & MVP & Retrofit + OKHttp & RecyclerView ...)Gank.io Android客户端:每天一张美女图片,一个视频短片,若干Android,iOS等程序干货,周一到周五每天更新,数据全部由 干货集中营 提供,持续更新。 |
[MNUpdateAPK](https://github.com/maning0303/MNUpdateAPK) | Android APK 版本更新的下载和安装,适配7.0,简单方便。 |
[MNImageBrowser](https://github.com/maning0303/MNImageBrowser) | 交互特效的图片浏览框架,微信向下滑动动态关闭 |
[MNCalendar](https://github.com/maning0303/MNCalendar) | 简单的日历控件练习,水平方向日历支持手势滑动切换,跳转月份;垂直方向日历选取区间范围。 |
[MClearEditText](https://github.com/maning0303/MClearEditText) | 带有删除功能的EditText |
[MNCrashMonitor](https://github.com/maning0303/MNCrashMonitor) | Debug监听程序崩溃日志,展示崩溃日志列表,方便自己平时调试。 |
[MNProgressHUD](https://github.com/maning0303/MNProgressHUD) | MNProgressHUD是对常用的自定义弹框封装,加载ProgressDialog,状态显示的StatusDialog和自定义Toast,支持背景颜色,圆角,边框和文字的自定义。 |
[MNXUtilsDB](https://github.com/maning0303/MNXUtilsDB) | xUtils3 数据库模块单独抽取出来,方便使用。 |
[MNVideoPlayer](https://github.com/maning0303/MNVideoPlayer) | SurfaceView + MediaPlayer 实现的视频播放器,支持横竖屏切换,手势快进快退、调节音量,亮度等。------代码简单,新手可以看一看。 |
[MNZXingCode](https://github.com/maning0303/MNZXingCode) | 快速集成二维码扫描和生成二维码 |
[MNChangeSkin](https://github.com/maning0303/MNChangeSkin) | Android夜间模式,通过Theme实现 |
[SwitcherView](https://github.com/maning0303/SwitcherView) | 垂直滚动的广告栏文字展示。 |
[MNPasswordEditText](https://github.com/maning0303/MNPasswordEditText) | 类似微信支付宝的密码输入框。 |
[MNSwipeToLoadDemo](https://github.com/maning0303/MNSwipeToLoadDemo) | 利用SwipeToLoadLayout实现的各种下拉刷新效果(饿了吗,京东,百度外卖,美团外卖,天猫下拉刷新等)。 |
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
</application>

</manifest>
6 changes: 6 additions & 0 deletions app/src/main/java/com/maning/crashmonitor/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.maning.crashmonitor;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
Expand All @@ -24,4 +25,9 @@ public void btn02(View view) {
MCrashMonitor.startCrashListPage(this);
}


public void btn03(View view) {
startActivity(new Intent(this,SecondActivity.class));
}

}
13 changes: 12 additions & 1 deletion app/src/main/java/com/maning/crashmonitor/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import android.app.Application;
import android.util.Log;

import com.maning.librarycrashmonitor.listener.CrashCallBack;
import com.maning.librarycrashmonitor.main.MCrashMonitor;

import java.io.File;

/**
* Created by maning on 2017/4/20.
*/
Expand All @@ -28,7 +31,15 @@ private void initCrashMonitor() {
* 初始化日志系统
* context : 上下文
* isDebug : 是不是Debug模式,true:崩溃后显示自定义崩溃页面 ;false:关闭应用,不跳转奔溃页面(默认)
* CrashCallBack : 回调执行
*/
MCrashMonitor.init(this, true);
MCrashMonitor.init(this, true, new CrashCallBack() {
@Override
public void onCrash(File file) {
//可以在这里重启应用
//可以在这里保存标识,下次再次进入把日志发送给服务器
Log.i(TAG, "CrashMonitor回调:" + file.getAbsolutePath());
}
});
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/maning/crashmonitor/SecondActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.maning.crashmonitor;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class SecondActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}

public void btn01(View view) {
//手动造成一个Crash
throw new NullPointerException("自定义异常抛出2");
}

}
12 changes: 8 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
android:padding="10dp">

<Button
android:layout_width="match_parent"
Expand All @@ -22,4 +19,11 @@
android:onClick="btn02"
android:text="日志列表页面" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="btn03"
android:text="下一页" />

</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_second.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context="com.maning.crashmonitor.SecondActivity">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="btn01"
android:text="抛出自定义异常" />

</LinearLayout>
Loading

0 comments on commit 8a36714

Please sign in to comment.