Commit 620ba824 authored by jianglx's avatar jianglx

修改图片保存路径

parent 56953f5b
...@@ -102,7 +102,11 @@ public class BillPresenter extends CommonPresenter { ...@@ -102,7 +102,11 @@ public class BillPresenter extends CommonPresenter {
public File saveBitmapFile(Bitmap bitmap) { public File saveBitmapFile(Bitmap bitmap) {
File file = new File(StorageUtils.getCachePath(getPresenterContext()) + System.currentTimeMillis() + ".jpg");//将要保存图片的路径 File parent = new File(StorageUtils.getPhotoSavePath(getPresenterContext()));
if (!parent.exists()) {
parent.mkdirs();
}
File file = new File(parent, System.currentTimeMillis() + ".jpg");//将要保存图片的路径
try { try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
......
...@@ -94,19 +94,32 @@ public class ReativeBillPresenter extends CommonPresenter { ...@@ -94,19 +94,32 @@ public class ReativeBillPresenter extends CommonPresenter {
} }
private File saveBitmapFile(Bitmap bitmap) { private File saveBitmapFile(Bitmap bitmap) {
File file = new File(StorageUtils.getCachePath(getPresenterContext()) + (int) (System.currentTimeMillis() / 1000000) + ".jpg");//将要保存图片的路径 File parent = new File(StorageUtils.getPhotoSavePath(getPresenterContext()));
if (!parent.exists()) {
parent.mkdirs();
}
File file = new File(parent, ((int) (System.currentTimeMillis() / 1000000)) + ".jpg");//将要保存图片的路径
if (file.exists()) { if (file.exists()) {
return file; return file;
} }
BufferedOutputStream bos = null;
try { try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush(); bos.flush();
bos.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
StorageUtils.notifyImageChange(getPresenterContext(), file.getPath());
return file; return file;
} }
} }
package com.rv.share.utils; package com.rv.share.utils;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import java.io.File;
public class StorageUtils { public class StorageUtils {
public static String getCachePath(Context context) { private final static String DIR = "image";
/********
* 获取图片保存路径
* @param context
* @return
*/
public static String getPhotoSavePath(Context context) {
String cachePath = null; String cachePath = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) { || !Environment.isExternalStorageRemovable()) {
cachePath = context.getExternalCacheDir().getPath(); cachePath = Environment.getExternalStorageDirectory().getPath();
} else { } else {
cachePath = context.getCacheDir().getPath(); cachePath = context.getCacheDir().getPath();
} }
return cachePath; return cachePath + File.separator + DIR + File.separator;
}
public static void notifyImageChange(Context context, String filePath) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(new File(filePath));
intent.setData(uri);
context.sendBroadcast(intent); // 发送广播通知相册
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment