This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 847
Can not get file path from FileProvider URI #85
Comments
Hi @NaikSoftware . Were u able to solve this? I got stuck on this one =/ |
any news on this? |
Any news? I've got the same issue. |
I ended up applied a quick-n-dirty fix:
then in my app
where
|
Thanks, but doesn't work for me. I have the folowing problem: I have to caputure an image from camera, so I'm doing this:
@OnClick(R.id.sendPhoto_button)
public void sendPhotoButton(View view) {
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mMediaUri = Util.getImageUri(this);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
imageCaptureIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (imageCaptureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE);
}
}
public static Uri getImageUri(Context context) {
File imageFile = createImageFile(context);
if (imageFile != null) {
return FileProvider.getUriForFile(context, AUTHORITY, imageFile);
}
return null;
}
public static File createImageFile(Context context) {
return createImageFile(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "jpg");
}
static File createMediaFile(File storageDirectory, String extension) {
// Create an mediaFile file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fileName = extension.toUpperCase() + "_" + timeStamp + "_";
File mediaFile = null;
try {
mediaFile = File.createTempFile(
fileName, /* prefix */
"." + extension, /* suffix */
storageDirectory /* directory */
);
} catch (IOException e) {
e.printStackTrace();
}
// Save a file: path for use with ACTION_VIEW intents
//mCurrentPhotoPath = mediaFile.getAbsolutePath();
return mediaFile;
} And this is me trying to get real path from uri public static String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.capture.image"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
... <?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="images" path="Android/data/com.capture.image/files/Pictures" />
</paths>
|
I suggest to take a look at https://github.com/ArthurHub/Android-Image-Cropper or just use it as a full handle-photo-capture library. Implementing photo capture and upload from scratch is pretty hard due to android manufacturers different implementations. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Uri generated with FileProvider not contain _data column
https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java#L233
The text was updated successfully, but these errors were encountered: