質問

SDカード上の画像、または少なくともカメラで撮影された画像を見つける方法を探しています。

理想的なソリューションは、画像のファイルパスまたはURIのコレクションを取得することです。 MediaStoreを介してこれを行うことができると思いますが、方法がわかりません。

ありがとう

役に立ちましたか?

解決

より多くのMediaStoreの例を調べた後、私はこれを思いつき、仕事を完了しました。

protected ArrayList<Uri> GetImageList(boolean getThumbs) 
{       
    ArrayList<Uri> images = new ArrayList<Uri>();
    String columnType;  
    Uri contentType;                
    String[] columnNames;

    if (getThumbs)
    {
         columnType = MediaStore.Images.Thumbnails._ID;
         contentType = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
    }
    else
    {
        columnType = MediaStore.Images.Media._ID;
        contentType = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    }

    columnNames = new String[]{columnType};             
    Cursor cursor = managedQuery(contentType, columnNames, null, null, null);       
    int columnIndex = cursor.getColumnIndexOrThrow(columnType);

    for(int i = 0; i < cursor.getCount(); i++)
    {
        cursor.moveToPosition(i);
        int id = cursor.getInt(columnIndex);
        images.add(Uri.withAppendedPath(contentType, "" + id));
    }

    return images;
}

すべての画像のUriまたはSDカード上のすべての画像のサムネイルのUriを返します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top