Import pictures from Android

Asked 2 years ago, Updated 2 years ago, 53 views

I'd like to get a picture from Android. When I googled, all I did was float the gallery in Intent, and if I chose the picture I wanted, I could only get the picture, but that's not what I wanted I want to scratch all the image files on the device, what should I do?

image android

2022-09-22 12:25

1 Answers

I googled and searched for all image files and found this data.

private ArrayList<String> getPathOfAllImages()
{
  ArrayList<String> result = new ArrayList<>();
  Uri uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
  String[] projection = { MediaColumns.DATA, MediaColumns.DISPLAY_NAME };

  Cursor cursor = getContentResolver().query(uri, projection, null, null, MediaColumns.DATE_ADDED + " desc");
  int columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
  int columnDisplayname = cursor.getColumnIndexOrThrow(MediaColumns.DISPLAY_NAME);

  int lastIndex;
  while (cursor.moveToNext())
  {
    String absolutePathOfImage = cursor.getString(columnIndex);
    String nameOfFile = cursor.getString(columnDisplayname);
    lastIndex = absolutePathOfImage.lastIndexOf(nameOfFile);
    lastIndex = lastIndex >= 0 ? lastIndex : nameOfFile.length() - 1;

    if (!TextUtils.isEmpty(absolutePathOfImage))
    {
      result.add(absolutePathOfImage);
    }
  }

  for (String string : result)
  {
    Log.i("PhotoSelectActivity.java | getPathOfAllImages", "|" + string + "|");
  }
  return result;
}


2022-09-22 12:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.