Java Code Examples for com.blankj.utilcode.util.PathUtils#getInternalAppFilesPath()

The following examples show how to use com.blankj.utilcode.util.PathUtils#getInternalAppFilesPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppStartInfoFragment.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
/**
 * 将启动信息保存到文件并分享
 */
private void export2File(final String info) {
    if (TextUtils.isEmpty(info)) {
        ToastUtils.showShort("启动信息为空");
        return;
    }
    ToastUtils.showShort("启动信息保存中,请稍后...");
    final String logPath = PathUtils.getInternalAppFilesPath() + File.separator + AppUtils.getAppName() + "_" + "app_launch.log";
    final File logFile = new File(logPath);

    ThreadUtils.executeByCpu(new ThreadUtils.Task<Boolean>() {
        @Override
        public Boolean doInBackground() throws Throwable {
            try {

                FileIOUtils.writeFileFromString(logFile, info, false);

                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }

        @Override
        public void onSuccess(Boolean result) {
            if (result) {
                ToastUtils.showShort("启动信息文件保存在:" + logPath);
                //分享
                FileUtil.systemShare(DoraemonKit.APPLICATION, logFile);
            }
        }

        @Override
        public void onCancel() {
            if (logFile.exists()) {
                FileUtils.delete(logFile);
            }
            ToastUtils.showShort("启动信息保存失败");
        }

        @Override
        public void onFail(Throwable t) {
            if (logFile.exists()) {
                FileUtils.delete(logFile);
            }
            ToastUtils.showShort("启动信息保存失败");
        }
    });

}
 
Example 2
Source File: LogInfoDokitView.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
/**
 * 将日志信息保存到文件
 *
 * @param operateType 100 保存到本地  101 保存到本地并分享
 */
private void export2File(final int operateType) {
    ToastUtils.showShort("日志保存中,请稍后...");
    final String logPath = PathUtils.getInternalAppFilesPath() + File.separator + AppUtils.getAppName() + "_" + TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")) + ".log";
    final File logFile = new File(logPath);

    ThreadUtils.executeByCpu(new ThreadUtils.Task<Boolean>() {
        @Override
        public Boolean doInBackground() throws Throwable {
            try {
                List<LogLine> logLines = new ArrayList<>(mLogItemAdapter.getTrueValues());
                for (LogLine logLine : logLines) {
                    String strLog = logLine.getProcessId() + "   " + "   " + logLine.getTimestamp() + "   " + logLine.getTag() + "   " + logLine.getLogLevelText() + "   " + logLine.getLogOutput() + "\n";
                    FileIOUtils.writeFileFromString(logFile, strLog, true);
                }
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }

        @Override
        public void onSuccess(Boolean result) {
            if (result) {
                ToastUtils.showShort("文件保存在:" + logPath);
                //分享
                if (operateType == 101) {
                    FileUtil.systemShare(DoraemonKit.APPLICATION, logFile);
                }
            }
        }

        @Override
        public void onCancel() {
            if (logFile.exists()) {
                FileUtils.delete(logFile);
            }
            ToastUtils.showShort("日志保存失败");
        }

        @Override
        public void onFail(Throwable t) {
            if (logFile.exists()) {
                FileUtils.delete(logFile);
            }
            ToastUtils.showShort("日志保存失败");
        }
    });

}