title: Making a GridView take images from a specific folder
body: <p>I am a newbie to android app making and I am still a beginner with a little knowledge . I have been trying to make an android app that works like a gallery , but it only displays images under a specific folder. For the UI , I am starting with only a <code>GridView</code> (or <code>TwoWayGridView</code> which is derived from the latter) , and have been trying to let this <code>GridView</code> take its contents from this folder .</p>
  
  <p>I have made this folder and copied an image to it for testing and failed. No image was displayed .Plus I am not very familiar with <code>Cursors</code> and <code>ListAdapters</code> . Somethings that I'm sure that are correct are permissions , manifest , and layout of the activity.Moreover , I believe my problem is around <code>URI</code>s . Please check my code below :</p>
  
  <p><strong>Some namings:</strong></p>
  
  <pre><code>Uri contentUri;
  
  Cursor mImageCursor;
  TwoWayGridView mImageGrid;
  ListAdapter mAdapter;
  
  String sdCard = Environment.getExternalStorageDirectory().getAbsolutePath();
  </code></pre>
  
  <p><strong>onCreate method :</strong></p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_gallery);
  
          File motherDirectory = new File(sdCard+"/Favory");
          if(!motherDirectory.exists()){
              motherDirectory.mkdir();
          }
  
  
          MediaScannerConnection.scanFile(this, new String[]{motherDirectory.getAbsolutePath()}   ,null, new MediaScannerConnection.OnScanCompletedListener() {
  
              @Override
              public void onScanCompleted(String path, Uri uri) {
                  // TODO Auto-generated method stub
                  contentUri = uri ;
                  initGrid(uri);
              }
          });
  
  
  
      }
  </code></pre>
  
  <p><strong>initGrid(Uri) method :</strong></p>
  
  <pre><code>private void initGrid(Uri folderUri) {
  
  
  
  mImageCursor = this.getContentResolver().query(folderUri,
          ImageThumbnailAdapter.IMAGE_PROJECTION, null, null,
          MediaStore.Images.ImageColumns.DISPLAY_NAME);
  mImageGrid = (TwoWayGridView) findViewById(R.id.gridview);
  mAdapter = new ImageThumbnailAdapter(this, mImageCursor);
  mImageGrid.setAdapter(mAdapter);
  
  mImageGrid.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(TwoWayAdapterView&lt;?&gt; parent, View v, int position, long id) {
          Log.i(TAG, "showing image: " + mImageCursor.getString(ImageThumbnailAdapter.IMAGE_NAME_COLUMN));
          Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
          Intent intent = new Intent(Intent.ACTION_VIEW, uri);
          startActivity(intent);
      }
  });
  }
  </code></pre>
  
  <p>Thanks for your help , and please if there is an easier alternative way of doing this tell me, I care for the results more than the methods now . If you need anything or any more information please tell me in the comments below . Thanks again !</p>