Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:19:07+00:00 2026-06-11T20:19:07+00:00

I have a created a android program to read videos from any specific folder

  • 0

I have a created a android program to read videos from any specific folder of sdcard and then display their thumbnails in Grid View.
However my program is working correctly for Movies folder in sdcard only.
Its not showing any videos for other folders in sdcard.

I have specified the name of the folder “Movies” at two places in my code.
Once in AdapterView.OnItemClickListener and another in initVideosId().

Now there is other folders also in my sdcard, say sdcard->geovideo

Now when I am specifying “geovideo” instead of “Movies” then it is showing nothing in my tablet. Do you have any idea what is the problem.

Anyone please help me to do my task.
Thanks.
Below is my android program

package com.vt.soc;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class MainActivity extends Activity {
    //set constants for MediaStore to query, and show videos
    private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    private final static String _ID = MediaStore.Video.Media._ID;
    private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
    //flag for which one is used for images selection
    private GridView _gallery; 
    private Cursor _cursor;
    private int _columnIndex;
    private int[] _videosId;
    private Uri _contentUri;
    String filename;
    int flag = 0;



    protected Context _context;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        _context = getApplicationContext();
        setContentView(R.layout.activity_main);
        //set GridView for gallery
        _gallery = (GridView) findViewById(R.id.videoGrdVw);
        //set default as external/sdcard uri
        _contentUri = MEDIA_EXTERNAL_CONTENT_URI;

        initVideosId();

        //set gallery adapter
        setGalleryAdapter();


    }
    private void setGalleryAdapter() {
        _gallery.setAdapter(new VideoGalleryAdapter(_context));
        _gallery.setOnItemClickListener(_itemClickLis);
        flag = 1;       
    }
    private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener() 
    {
        @SuppressWarnings({ "deprecation", "unused", "rawtypes" })
        public void onItemClick(AdapterView parent, View v, int position, long id) 
        {
            // Now we want to actually get the data location of the file
            String [] proj={MEDIA_DATA};
            // We request our cursor again
            _cursor = managedQuery(_contentUri,
                    proj, // Which columns to return
                    MEDIA_DATA + " like ? ",       // WHERE clause; which rows to return (all rows)
                    new String[] {"%Movies%"},       // WHERE clause selection arguments (none)
                    null); // Order-by clause (ascending by name)
            // We want to get the column index for the data uri
            int count = _cursor.getCount();
            //
            _cursor.moveToFirst();
            //
            _columnIndex = _cursor.getColumnIndex(MEDIA_DATA);
            // Lets move to the selected item in the cursor
            _cursor.moveToPosition(position);
            // And here we get the filename
            filename = _cursor.getString(_columnIndex);
            //*********** You can do anything when you know the file path :-)
            showToast(filename);

            Intent i = new Intent(MainActivity.this, Player.class); 
            i.putExtra("videoPath", filename);
            startActivity(i);


            //
        }
    };
    @SuppressWarnings("deprecation")
    private void initVideosId() {
        try
        {
            //Here we set up a string array of the thumbnail ID column we want to get back
            String [] proj={_ID};
            // Now we create the cursor pointing to the external thumbnail store
            _cursor = managedQuery(_contentUri,
                    proj, // Which columns to return
                    MEDIA_DATA + " like ? ",       // WHERE clause; which rows to return (all rows)
                    new String[] {"%Movies%"},       // WHERE clause selection arguments (none)
                    null); // Order-by clause (ascending by name)
            int count= _cursor.getCount();
            // We now get the column index of the thumbnail id
            _columnIndex = _cursor.getColumnIndex(_ID);
            //initialize 
            _videosId = new int[count];
            //move position to first element
            _cursor.moveToFirst();          
            for(int i=0;i<count;i++)
            {           
                int id = _cursor.getInt(_columnIndex);
                //
                _videosId[i]= id;
                //
                _cursor.moveToNext();
                //
            }
        }catch(Exception ex)
        {
            showToast(ex.getMessage().toString());          
        }

    }
    protected void showToast(String msg)
    {
        Toast.makeText(_context, msg, Toast.LENGTH_LONG).show();
    }

    //
    private class VideoGalleryAdapter extends BaseAdapter
    {
        public VideoGalleryAdapter(Context c) 
        {
            _context = c;
        }
        public int getCount() 
        {
            return _videosId.length;
        }
        public Object getItem(int position) 
        {
            return position;
        }
        public long getItemId(int position) 
        {
            return position;
        }
        public View getView(int position, View convertView, ViewGroup parent) 
        {
            ImageView imgVw= new ImageView(_context);;
            try
            {
                if(convertView!=null)
                {
                    imgVw= (ImageView) convertView;
                }
                imgVw.setImageBitmap(getImage(_videosId[position]));
                imgVw.setLayoutParams(new GridView.LayoutParams(200, 200));
                imgVw.setPadding(8, 8, 8, 8);
            }
            catch(Exception ex)
            {
                System.out.println("MainActivity:getView()-135: ex " + ex.getClass() +", "+ ex.getMessage());
            }
            return imgVw;
        }

        // Create the thumbnail on the fly
        private Bitmap getImage(int id) {
            Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(
                    getContentResolver(),
                    id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
            return thumb;
        }

    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:19:08+00:00Added an answer on June 11, 2026 at 8:19 pm

    Actually problem was the user permission in my manifest file.

    I hope any one who face the same problem as mine,
    will be happy to see my answser.

    Actually, Movies folder was in built folder in sdcard
    and as I mentioned that I have my own folder ‘geovideo’ in sdcard
    Which I was not able to see via my program.
    So I need to specify the permission in Manifest file.

    When I added

     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    

    to my manifest.
    It’s working.
    So just simple advice,
    When your program is not working think about permission as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my android code wherein I fetch all the data from facebook
In my android app I have created a raw folder inside /res folder (/res/raw).
I have created a sample android NDK program in eclipse. I'm working with Windows
I have created a sample Hello World program in android it was working fine
I have successfully created an Android app that calculates prices and then is able
I have created a sample/demo/test program in Android that runs quite nicely, if you
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a MazeSolver android app for a school project. I am using
I have created following thing in android using android compatibility support package Basically i
I have created a listview with 3 rows in Android. If I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.