Java how to get path of captured image in android

Java how to get path of captured image in android

To get the path of a captured image in an Android app, you can use the FileProvider class to generate a content URI for the image and pass it to the MediaStore class to save the image in the device's external storage. The MediaStore class provides a method to query the database for the saved image and return the path.

Here's an example of how you can get the path of a captured image in an Android app:

re‮ ref‬to:lautturi.com
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

// ...

private void saveImage(Bitmap image, Context context) {
    // Create a content values object with the image data
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.MediaColumns.DATA, imagePath);

    // Insert the image into the MediaStore
    Uri imageUri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    
}
Created Time:2017-11-03 23:27:09  Author:lautturi