bubu uwu
bubu uwu

Reputation: 483

get pictures's filepath taken by camera

I want to get the pictures which were taken by only device camera.

Maybe, filepath name have DCIM or other things.

Here is code, is this ok? target API is bitween 15~21API.

/**
 * @param context
 * @returnArrayList with images Path
 */
public static ArrayList<String> getAllShownImagesPath(Context context) {
    Uri uri;
    Cursor cursor;
    int column_index_data, column_index_folder_name;
    ArrayList<String> listOfAllImages = new ArrayList<String>();
    String absolutePathOfImage = null;
    uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    final String DCIMPath = android.os.Environment.DIRECTORY_DCIM;
    Log.d(TAG, "DCIMPath #"+DCIMPath);

    String[] projection = { MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME };

    cursor = context.getContentResolver().query(uri, projection, null, null, null);

    column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
    column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
    while (cursor.moveToNext()) {
        absolutePathOfImage = cursor.getString(column_index_data);
        if(absolutePathOfImage.contains(DCIMPath))
            listOfAllImages.add(absolutePathOfImage);
    }

    String filepath = Environment.getExternalStorageDirectory().toString();
    Log.d(TAG, "filepath #" + filepath);

    return listOfAllImages;
}

I only tests one device it worked. but android device is so many.

Upvotes: 0

Views: 43

Answers (1)

Brian
Brian

Reputation: 313

If you want to get the default pictures storage directory on your device, try :

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

Upvotes: 1

Related Questions