Get all photos from Android device android programming

前端 未结 2 1302
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 09:21

I am trying to fetch all the photos of my android device.

I have an onCreate function:

public void onCreate(Bundle savedInstanceState)          


        
2条回答
  •  遥遥无期
    2021-01-19 09:32

    First do not forget to

     
    

    This method will return list of photo in your gallery

    public static ArrayList getImagesPath(Activity activity) {
        Uri uri;
        ArrayList listOfAllImages = new ArrayList();
        Cursor cursor;
        int column_index_data, column_index_folder_name;
        String PathOfImage = null;
        uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    
        String[] projection = { MediaColumns.DATA,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME };
    
        cursor = activity.getContentResolver().query(uri, projection, null,
                null, null);
    
        column_index_data = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
        column_index_folder_name = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
        while (cursor.moveToNext()) {
            PathOfImage = cursor.getString(column_index_data);
    
            listOfAllImages.add(PathOfImage);
        }
        return listOfAllImages;
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题