이미지 내보내기 기능이있는 이미지 편집 앱이 있습니다. 이전에는 파일 경로 uri를 ACTION_SEND 의도로 전달하여 직접 내보내려고했습니다. 예 :Android MediaStore에서 이미지 데이터를 가져올 수 없습니다.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, getString(R.string.export)));
그러나 모든 앱이 이러한 의도를 올바르게 구문 분석 할 수있는 것은 아닙니다. 이제는 먼저 이미지를 안드로이드의 MediaStore에 추가하여 uri를 준비합니다 :
shareUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(),
file.getAbsolutePath(), file.getName(), projectName));
... 그리고 shareUri를 intent로 전달합니다. 이제 모든 앱이이 의도를 올바르게 처리 할 수 있지만, 사용자가 이미지를 내 보내면 이미지 사본과 이미지 이름이 같은 경우에도 Android MediaStore에 사본이 추가 될 때마다 한 가지 문제가 나타납니다.
내가 결정하려고 이미 다음 코드에 의해 미디어 스토어 MediaStore에 추가 이미지 :
Cursor c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Images.Media.DATA + "=?",
new String[] { filePath }, null);
if (c.getCount() > 0 && c.moveToFirst()) {
shareUri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
"" + c.getInt(c.getColumnIndex(MediaStore.Images.Media._ID)));
c.close();
} else {
shareUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(),
file.getAbsolutePath(), file.getName(), projectName));
}
...하지만 c.getCount()는 항상 == 0 내가 MediaStore.Images에서 저장된 URI를 복사 할 경우에도 마찬가지입니다. Media.insertImage로 직접 문의하십시오.
Cursor c = getContentResolver().query(savedUri, null, null, null);
MediaStore에서 이미 이미지 파일을 감지 할 수 있습니까?