1

This is my layout gallery //gallery.xml

    <FrameLayout android:id="@+id/FrameLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">


        <FrameLayout android:id="@+id/LinearLayout01"
            android:layout_gravity="top" 
            android:layout_height="50dp" 
            android:layout_width="fill_parent">

             <Button android:layout_gravity="left" 
                android:id="@+id/btnPhotos" 
                android:layout_marginRight="5dp" 
                android:layout_marginTop="5dp" 
                android:textStyle="bold" 
                android:layout_width="100dp" 
                android:layout_height="40dp"
                android:text="Photos"/>

            <TextView android:id="@+id/TextViewAlbumName"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:textStyle="bold" 
                android:layout_gravity="center" 
                android:text="Album Name"
                />

            <Button android:layout_gravity="right" 
                android:id="@+id/btnCancel" 
                android:layout_marginRight="5dp" 
                android:layout_marginTop="5dp" 
                android:textStyle="bold" 
                android:layout_width="100dp" 
                android:layout_height="wrap_content" android:text="Cancel"/>
        </FrameLayout>

        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/gridview" 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:columnWidth="90dp"
            android:numColumns="auto_fit" 
            android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp" 
            android:stretchMode="columnWidth"
            android:gravity="center" 
            android:layout_gravity="bottom"
            android:layout_marginTop="50dp"/>

    </FrameLayout>

My question is how can I display in my gridview all image gallery? I know about How to pick an image from gallery (SD Card) for my app? but I need to stay in my app and get the name of the albums too.

Community
  • 1
  • 1

1 Answers1

-1

Do you want to just display all the images on the phone? Or do you want to display it like the gallery app and display the folders first?

EDIT: Here is code to get all images on your devices, internal and external NOTE you will need permission to read SD-Card in order for this to work.

//This gets all external images
    String[] mProjection = {MediaStore.Images.Media.DATE_TAKEN,MediaStore.Images.Media.DATA};
                    Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,mProjection,null,null,MediaStore.Images.Media.DATE_ADDED);

//This gets all internal images
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.INTERNAL_CONTENT_URI,mProjection,null,null,MediaStore.Images.Media.DATE_ADDED);

Notice i passed in date_taken and data as the query, so to get those fields, you would do

while(cursor.moveToNext()){
 long date =cursor.getLong(0);
 String fileLoc=cursor.getString(1);

}

You can then display images based on their location, order them by date, etc...

KennyC
  • 593
  • 4
  • 12