Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get all images from sd-card (android-gallery) ?
    primarykey
    data
    text
    <p>In my app I need to implement an option for the user to select images from sd-card or phone memory. I have used custom cover-flow to animate the images. I have written a code to retrieve images from sd-card using cursor. But I get only few images, not all. And these images are displayed multiple times in my cover-flow. Each image is displaying twice.</p> <p>If there are no images on sd-card then app crashes.</p> <p>Here is my code, Please somebody help</p> <pre><code>public class CoverFlowActivityMain extends Activity { private Cursor cursor; private int columnIndex; private File file; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CoverFlow coverFlow; coverFlow = new CoverFlow(this); file = new File("/sdcard/"); // I am using this file to check iamges on sd-card, // but this does not search files in subdirectories. File[] allFiles = file.listFiles(); for(int i=0; i&lt;allFiles.length; i++) { Log.v("File: "+i, ""+allFiles[i].getName().toString()); } // Set up an array of the Thumbnail Image ID column we want String[] projection = {MediaStore.Images.Thumbnails._ID}; // Create the cursor pointing to the SDCard cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, // Which columns to return null, // Return all rows null, MediaStore.Images.Thumbnails.IMAGE_ID); // Get the column index of the Thumbnails Image ID columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID); coverFlow.setAdapter(new ImageAdapter(this)); ImageAdapter coverImageAdapter = new ImageAdapter(this); coverFlow.setAdapter(coverImageAdapter); coverFlow.setSpacing(-5); coverFlow.setSelection(0, true); coverFlow.setAnimationDuration(1500); setContentView(coverFlow); } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; public ImageAdapter(Context c) { mContext = c; } public int getCount() { return cursor.getCount(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { //-- Use this code if you want to load from sdcard --\\ ImageView picturesView; if (convertView == null) { picturesView = new ImageView(mContext); // Move cursor to current position cursor.moveToPosition(position); // Get the current value for the requested column int imageID = cursor.getInt(columnIndex); // Set the content of the image based on the provided URI picturesView.setImageURI(Uri.withAppendedPath( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID)); picturesView.setLayoutParams(new CoverFlow.LayoutParams(380, 450)); picturesView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); //Make sure we set anti-aliasing otherwise we get jaggies BitmapDrawable drawable = (BitmapDrawable) picturesView.getDrawable(); drawable.setAntiAlias(true); } else { picturesView = (ImageView)convertView; } return picturesView; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload