Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

23 changes: 0 additions & 23 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/dictionaries/wenmingvs.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

8 changes: 1 addition & 7 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

49 changes: 1 addition & 48 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "23.0.3"
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "com.wenming.crashcachedemo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private void initCrashReport() {
.setCacheSize(30 * 1024 * 1024)//支持设置缓存大小,超出后清空
.setLogDir(getApplicationContext(), "sdcard/" + this.getString(this.getApplicationInfo().labelRes) + "/")//定义路径为:sdcard/[app name]/
.setWifiOnly(true)//设置只在Wifi状态下上传,设置为false为Wifi和移动网络都上传
.setCrashOnly(false)
.setLogSaver(new CrashWriter(getApplicationContext()))//支持自定义保存崩溃信息的样式
//.setEncryption(new AESEncode()) //支持日志到AES加密或者DES加密,默认不开启
.init(getApplicationContext());
Expand All @@ -33,7 +34,7 @@ private void initCrashReport() {
*/
private void initEmailReporter() {
EmailReporter email = new EmailReporter(this);
email.setReceiver("wenmingvs@gmail.com");//收件人
email.setReceiver("zhujinhu21@163.com");//收件人
email.setSender("wenmingvs@163.com");//发送人邮箱
email.setSendPassword("apptest1234");//邮箱密码
email.setSMTPHost("smtp.163.com");//SMTP地址
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ systemProp.http.proxyPort=1080
org.gradle.jvmargs=-Xmx3062m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
android.enableAapt2=false
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon Dec 28 10:00:20 PST 2015
#Thu Jun 07 11:54:53 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2 changes: 1 addition & 1 deletion logreport/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "23.0.3"
buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 14
Expand Down
10 changes: 10 additions & 0 deletions logreport/src/main/java/com/wenming/library/LogReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class LogReport {
*/
private boolean mWifiOnly = true;

/**
* 设置是否在奔溃下才上传,true为只在奔溃模式下上传,false是都上传
*/
private boolean mCrashOnly=true;

private LogReport() {
}
Expand Down Expand Up @@ -85,6 +89,11 @@ public LogReport setWifiOnly(boolean wifiOnly) {
return this;
}

public LogReport setCrashOnly(boolean crashOnly) {
mCrashOnly = crashOnly;
return this;
}


public LogReport setLogDir(Context context, String logDir) {
if (TextUtils.isEmpty(logDir)) {
Expand Down Expand Up @@ -149,6 +158,7 @@ public void upload(Context applicationContext) {
return;
}
Intent intent = new Intent(applicationContext, UploadService.class);
intent.putExtra("mCrashOnly", mCrashOnly);
applicationContext.startService(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class UploadService extends IntentService {

public static final String TAG = "UploadService";

boolean mCrashOnly;
/**
* 压缩包名称的一部分:时间戳
*/
Expand All @@ -39,6 +39,11 @@ public void onCreate() {
super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mCrashOnly = intent.getBooleanExtra("mCrashOnly",true);
return super.onStartCommand(intent, flags, startId);
}
/**
* 同一时间只会有一个耗时任务被执行,其他的请求还要在后面排队,
* onHandleIntent()方法不会多线程并发执行,所有无需考虑同步问题
Expand All @@ -53,12 +58,15 @@ protected void onHandleIntent(Intent intent) {
LogUtil.d("Log文件夹都不存在,无需上传");
return;
}
//只存在log文件,但是不存在崩溃日志,也不会上传
ArrayList<File> crashFileList = FileUtil.getCrashList(logfolder);
if (crashFileList.size() == 0) {
LogUtil.d(TAG, "只存在log文件,但是不存在崩溃日志,所以不上传");
return;
if(mCrashOnly){
//只存在log文件,但是不存在崩溃日志,也不会上传
if (crashFileList.size() == 0) {
LogUtil.d(TAG, "只存在log文件,但是不存在崩溃日志,所以不上传");
return;
}
}

File zipfolder = new File(LogReport.getInstance().getROOT() + "AlreadyUploadLog/");
File zipfile = new File(zipfolder, "UploadOn" + ZIP_FOLDER_TIME_FORMAT.format(System.currentTimeMillis()) + ".zip");
final File rootdir = new File(LogReport.getInstance().getROOT());
Expand Down