سؤال

وأنا أبحث عن وسيلة للعثور على صور على بطاقة SD، أو على الأقل الصور بواسطة الكاميرا اتخاذها.

والحل المثالي أن يكون الحصول على مجموعة من مسارات الملفات أو محددات للصور. أنا التخمين يمكنك القيام بذلك من خلال 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;
}

وإرجاع أوري جميع الصور أو أوري من الصورة المصغرة لجميع الصور على SDCARD.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top