补充日志分享为打包压缩文件
This commit is contained in:
parent
3f9cf21b8f
commit
c4f3d10419
@ -274,7 +274,7 @@ public class AppContext extends CommonAppContext {
|
|||||||
});
|
});
|
||||||
configSPApp();
|
configSPApp();
|
||||||
//初始化美颜SDK
|
//初始化美颜SDK
|
||||||
// FaceManager.initFaceUnity(this);
|
// FaceManager.initFaceUnity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,15 +28,24 @@ import com.lzy.okserver.upload.UploadListener;
|
|||||||
import com.lzy.okserver.upload.UploadTask;
|
import com.lzy.okserver.upload.UploadTask;
|
||||||
import com.yunbao.common.CommonAppConfig;
|
import com.yunbao.common.CommonAppConfig;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cxf on 2019/6/20.
|
* Created by cxf on 2019/6/20.
|
||||||
@ -77,15 +86,15 @@ public class LogUtil {
|
|||||||
Log.i("异常上传", "pushError: 准备上传文件");
|
Log.i("异常上传", "pushError: 准备上传文件");
|
||||||
String err = FileUtil.loadStringToFile(file);
|
String err = FileUtil.loadStringToFile(file);
|
||||||
String time = matcher(".(?<=time\\=).*(?=\\AndroidVersion\\=)", err);
|
String time = matcher(".(?<=time\\=).*(?=\\AndroidVersion\\=)", err);
|
||||||
if(time!=null){
|
if (time != null) {
|
||||||
time=time.replace("=","");
|
time = time.replace("=", "");
|
||||||
}else{
|
} else {
|
||||||
time=System.currentTimeMillis()+"";
|
time = System.currentTimeMillis() + "";
|
||||||
}
|
}
|
||||||
PostRequest<String> request = OkGo.<String>post("https://newht.yaoulive.com/index.php/api/error_log/report")
|
PostRequest<String> request = OkGo.<String>post("https://newht.yaoulive.com/index.php/api/error_log/report")
|
||||||
.params("log", err)
|
.params("log", err)
|
||||||
.params("uid", CommonAppConfig.getInstance().getUid())
|
.params("uid", CommonAppConfig.getInstance().getUid())
|
||||||
.params("time",time)
|
.params("time", time)
|
||||||
.params("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY)
|
.params("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY)
|
||||||
.params("appVersion", CommonAppConfig.getInstance().getVersion())
|
.params("appVersion", CommonAppConfig.getInstance().getVersion())
|
||||||
.tag("errorLog")
|
.tag("errorLog")
|
||||||
@ -141,41 +150,63 @@ public class LogUtil {
|
|||||||
|
|
||||||
|
|
||||||
public static void shareFile(Context context) {
|
public static void shareFile(Context context) {
|
||||||
if(PermissionChecker.checkCallingOrSelfPermission(context,"android.permission.WRITE_EXTERNAL_STORAGE")!= PERMISSION_GRANTED){
|
if (PermissionChecker.checkCallingOrSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
|
||||||
ActivityCompat.requestPermissions((Activity) context,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100);
|
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
|
String title = "[PDLIVE]" + CommonAppConfig.getInstance().getUid() + "_";
|
||||||
File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
|
String today = title + SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
|
||||||
if (file.exists()) {
|
File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator);
|
||||||
|
File zip = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".zip");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zip)));
|
||||||
|
FileInputStream fis = null;
|
||||||
|
WritableByteChannel writableByteChannel = Channels.newChannel(zos);
|
||||||
|
if (dir.listFiles() != null) {
|
||||||
|
for (File file : dir.listFiles()) {
|
||||||
|
if (file.getName().endsWith(".log") && !"error.log".equals(file.getName())) {
|
||||||
|
ZipEntry entry = new ZipEntry(file.getName());
|
||||||
|
zos.putNextEntry(entry);
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
FileChannel channel = fis.getChannel();
|
||||||
|
channel.transferTo(0, file.length() - 1, writableByteChannel);
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zos.close();
|
||||||
|
writableByteChannel.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (zip.exists()) {
|
||||||
Intent share = new Intent(Intent.ACTION_SEND);
|
Intent share = new Intent(Intent.ACTION_SEND);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
|
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", zip);
|
||||||
share.putExtra(Intent.EXTRA_STREAM, contentUri);
|
share.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
} else {
|
} else {
|
||||||
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(zip));
|
||||||
}
|
}
|
||||||
share.setType("application/vnd.ms-excel");
|
share.setType("application/vnd.ms-excel");
|
||||||
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
context.startActivity(Intent.createChooser(share, "分享文件"));
|
context.startActivity(Intent.createChooser(share, "分享文件"));
|
||||||
}
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (!Environment.isExternalStorageManager()) {
|
||||||
if(!Environment.isExternalStorageManager()){
|
Intent intent = new Intent(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
||||||
Intent intent=new Intent(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
context.startActivity(intent);
|
||||||
context.startActivity(intent);
|
}
|
||||||
}
|
}
|
||||||
}
|
File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + zip.getName());
|
||||||
File out = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + file.getName());
|
try {
|
||||||
file.renameTo(out);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
Log.i("文件", "shareFile: "+out.getAbsolutePath()+" "+out.exists());
|
Files.copy(zip.toPath(), out.toPath());
|
||||||
try {
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
} catch (Exception e) {
|
||||||
Files.copy(file.toPath(),out.toPath());
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user