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