public static boolean saveImage(String url, String ext) { if (TextUtils.isEmpty(url)) { return false; } String filePath = url; File dir = new File(FileAccessor.APPS_ROOT_DIR, "ECDemo_IM"); if (!dir.exists()) dir.mkdirs(); long timeMillis = System.currentTimeMillis(); int result = FileUtils.copyFile( dir.getAbsolutePath(), "ecexport" + timeMillis, ext, FileUtils.readFlieToByte(filePath, 0, FileUtils.decodeFileLength(filePath))); if (result == 0) { ExportImgUtil.refreshingMediaScanner( CCPAppManager.getContext(), "ecexport" + timeMillis + ext); ToastUtil.showMessage("图片已保存至" + dir.getAbsolutePath(), Toast.LENGTH_LONG); return false; } ToastUtil.showMessage("图片保存失败"); return true; }
/** 获取图片存储文件夹路径 */ public static File getImagePath(Context context, String userNo, String orderId) { // 未安装SD卡时不做保存 String storageState = Environment.getExternalStorageState(); if (!storageState.equals(Environment.MEDIA_MOUNTED)) { ToastUtil.showToast(context, "未检测到SD卡", Toast.LENGTH_SHORT); return null; } // 图片文件保存路径 File storageDirectory = Environment.getExternalStorageDirectory(); File path = new File(storageDirectory, "/GZRJWorkassistant/image/" + userNo + "/" + orderId); // 图片路径不存在创建之 if (!path.exists()) { path.mkdirs(); } return path; }
private void pressAgainToExit() { long current = System.currentTimeMillis(); long duration = (current - lastPressBackTime) / 1000; if (duration <= PRESS_AGAIN_LIMIT_DURATION) { runOnUiThread( new Runnable() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } // exitApp(); finish(); } }); } else { lastPressBackTime = current; ToastUtil.showToast(getApplicationContext(), getString(R.string.press_again_to_exit)); } }