作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将我的图像保存在与我的应用程序名称相对应的文件夹中,而不是默认的“图片”文件夹中。这是我在 onRequestPermissionsResult 中的代码:
if(requestCode == SAVE_IMAGE) {
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + R.string.app_name + "/";
File dir = new File(path);
if(!dir.exists()){
dir.mkdirs();
}
OutputStream out;
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File photoFile = new File(path, timeStamp + ".jpg");
photoFile.createNewFile();
out = new FileOutputStream(photoFile);
Bitmap full_image_result = full_image.copy(full_image.getConfig(), true);
selectedFilter.apply(full_image_result);
full_image_result.compress(Bitmap.CompressFormat.JPEG, 90, out);
MediaStore.Images.Media.insertImage(MainActivity.this.getContentResolver(),photoFile.getAbsolutePath(), photoFile.getName(), photoFile.getName());
out.flush();
out.close();
Toast.makeText(getApplicationContext(),R.string.savedMessage, Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), R.string.noPermissions, Toast.LENGTH_LONG).show();
}
}
最佳答案
不知何故路径错误,将其替换为 Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictura/"
现在它正在工作。我还将 insertImage 调用替换为
MediaScannerConnection.scanFile(this, new String[]{photoFile.getAbsolutePath()}, new String[]{"image/jpg"}, null);
关于android - 为什么 MediaStore.Images.Media.insertImage 总是将图像保存在 Pictures 文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60376384/
我是一名优秀的程序员,十分优秀!