修复了保存图片但是系统图库没有显示的问题
This commit is contained in:
@ -370,7 +370,7 @@ public class MessageShareUtils {
|
||||
if (isToast) {
|
||||
Utils.toast(mContext, "图片已保存到/Pictures/ghzhushou/");
|
||||
//刷新手机图片库
|
||||
refreshImage(_file, mContext);
|
||||
refreshImage(mContext, _file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -388,12 +388,15 @@ public class MessageShareUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshImage(File _file, Context context) {
|
||||
/**
|
||||
* 注意,第二个入参需要是 file 本身而不是 folder
|
||||
*/
|
||||
public static void refreshImage(Context context, File imageFile) {
|
||||
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
||||
Uri uri = Uri.fromFile(_file);
|
||||
Uri uri = Uri.fromFile(imageFile);
|
||||
intent.setData(uri);
|
||||
context.sendBroadcast(intent);
|
||||
Utils.log("保存分享图片路径:" + _file.getAbsolutePath());
|
||||
Utils.log("保存分享图片路径:" + imageFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
class ShareRecyclerViewAdapter extends RecyclerView.Adapter<ShareRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
@ -393,7 +393,7 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
OutputStream outStream = new FileOutputStream(targetFile);
|
||||
outStream.write(resource.read());
|
||||
Utils.toast(ViewImageActivity.this, "图片已保存到/Pictures/ghzhushou/");
|
||||
MessageShareUtils.refreshImage(new File(savePath), ViewImageActivity.this);
|
||||
MessageShareUtils.refreshImage(ViewImageActivity.this, targetFile);
|
||||
} catch (Exception e) {
|
||||
Utils.log("图片保存失败:" + e.toString());
|
||||
e.printStackTrace();
|
||||
@ -430,7 +430,7 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
out.close();
|
||||
Utils.log("图片保存成功");
|
||||
Utils.toast(ViewImageActivity.this, "图片已保存到/Pictures/ghzhushou/");
|
||||
MessageShareUtils.refreshImage(new File(savePath), ViewImageActivity.this);
|
||||
MessageShareUtils.refreshImage(ViewImageActivity.this, f);
|
||||
} catch (IOException e) {
|
||||
Utils.log("图片保存失败:" + e.toString());
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user