单击图像视图时,我需要您的帮助来选择图像,然后将其保存在自定义文件夹中。
首先,这是我的源代码(在 onCreate 中):
//Permissions
//WRITE_EXTERNAL_STORAGE
boolean hasPermission = (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
if (!hasPermission) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_WRITE_STORAGE);
}
//Events
ivLogo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createFolder("InspectionApp");
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator
+ "DCIM"
+ File.separator
+ "InspectionApp"
+ File.separator
, "logo.jpg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
“InspectionApp”文件夹已成功创建为android DCIM的子文件夹。
图库应用会在点击时打开,但所选图片不会在我的自定义文件夹中保存为 logo.jpg 。
我没有收到任何错误消息,我知道使用日志会触发 onActivityResult 。
我做了一些与ACTION_IMAGE_CAPTURE类似的东西,它就像一个魅力,但ACTION_PICK没有:(
非常感谢你的帮助!
答案 0 :(得分:0)
我不知道ACTION_PICK和EXTRA_OUTPUT是否在ACTION_IMAGE_CAPTURE一起工作,但这个链接帮助我实现了我的目标: