diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 5fccbeebf..e1ddc7225 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -274,7 +274,7 @@ public class AppContext extends CommonAppContext { }); configSPApp(); //初始化美颜SDK - // FaceManager.initFaceUnity(this); + // FaceManager.initFaceUnity(this); } /** diff --git a/common/src/main/java/com/yunbao/common/utils/LogUtil.java b/common/src/main/java/com/yunbao/common/utils/LogUtil.java index 128ab9f74..47c4c8ea7 100644 --- a/common/src/main/java/com/yunbao/common/utils/LogUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/LogUtil.java @@ -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 request = OkGo.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(); } }