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

  • Home
  • SEARCH
  • 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 4267284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:52:42+00:00 2026-05-21T06:52:42+00:00

Hii i am working on an application in which i require to select files

  • 0

Hii i am working on an application in which i require to select files using browse button..
How can i implement a browse button in android?

  • 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-05-21T06:52:43+00:00Added an answer on May 21, 2026 at 6:52 am

    Below is the whole code from my sample application. I used a button which will pick files from any directory of your phone.

    layouts

    file_picker_empty_view.xml

    <TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="No files or directories"
    android:background="@android:drawable/toast_frame"
    android:textSize="28sp"
    android:gravity="center_vertical|center_horizontal"/>
    

    file_picker_list_item.xml

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal" >
      <ImageView
          android:id="@+id/file_picker_image"
          android:layout_width="40dip"
          android:layout_height="40dip"
          android:layout_marginTop="5dip"
          android:layout_marginBottom="5dip"
          android:layout_marginLeft="5dip"
          android:src="@drawable/file"
          android:scaleType="centerCrop"/>
      <TextView
          android:id="@+id/file_picker_text"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:layout_gravity="left|center_vertical"
          android:textSize="28sp"
          android:layout_marginLeft="10dip"
          android:singleLine="true"
          android:text="filename"/>
    </LinearLayout>
    

    file_view.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" 
    android:orientation="vertical"
    android:layout_width="fill_parent">
        <TextView android:text="@+id/TextView01" 
        android:id="@+id/TextView01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:singleLine="true" 
        android:textStyle="bold" 
        android:layout_marginTop="5dip" 
        android:layout_marginLeft="5dip"></TextView>
        <TextView android:text="@+id/TextView02" 
        android:id="@+id/TextView02" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="10dip"></TextView>
    </LinearLayout>
    

    main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical">
        <Button android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/start_file_picker_button"
            android:text="Browse" />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Selected file"
            android:textStyle="bold"
            android:textColor="#fff"
            android:textSize="24sp" />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/file_path_text_view"
            android:text="No file has been selected"
            android:textSize="18sp" />
    </LinearLayout>
    

    Activities are

    FilePickerActivity

    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.List;
    import android.app.ListActivity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.ImageView;
    import android.widget.ListView;
    import android.widget.TextView;
    
    /**
     * 
     * @author pankaj
     *
     */
    public class FilePickerActivity extends ListActivity {
    
        public final static String EXTRA_FILE_PATH = "file_path";
        public final static String EXTRA_SHOW_HIDDEN_FILES = "show_hidden_files";
        public final static String EXTRA_ACCEPTED_FILE_EXTENSIONS = "accepted_file_extensions";
        private final static String DEFAULT_INITIAL_DIRECTORY = "/";
    
        protected File mDirectory;
        protected ArrayList<File> mFiles;
        protected FilePickerListAdapter mAdapter;
        protected boolean mShowHiddenFiles = false;
        protected String[] acceptedFileExtensions;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // Set the view to be shown if the list is empty
            LayoutInflater inflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View emptyView = inflator.inflate(R.layout.file_picker_empty_view, null);
            ((ViewGroup)getListView().getParent()).addView(emptyView);
            getListView().setEmptyView(emptyView);
    
            // Set initial directory
            mDirectory = new File(DEFAULT_INITIAL_DIRECTORY);
    
            // Initialize the ArrayList
            mFiles = new ArrayList<File>();
    
            // Set the ListAdapter
            mAdapter = new FilePickerListAdapter(this, mFiles);
            setListAdapter(mAdapter);
    
            // Initialize the extensions array to allow any file extensions
            acceptedFileExtensions = new String[] {};
    
            // Get intent extras
            if(getIntent().hasExtra(EXTRA_FILE_PATH)) {
                mDirectory = new File(getIntent().getStringExtra(EXTRA_FILE_PATH));
            }
            if(getIntent().hasExtra(EXTRA_SHOW_HIDDEN_FILES)) {
                mShowHiddenFiles = getIntent().getBooleanExtra(EXTRA_SHOW_HIDDEN_FILES, false);
            }
            if(getIntent().hasExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS)) {
                ArrayList<String> collection = getIntent().getStringArrayListExtra(EXTRA_ACCEPTED_FILE_EXTENSIONS);
                acceptedFileExtensions = (String[]) collection.toArray(new String[collection.size()]);
            }
        }
    
        @Override
        protected void onResume() {
            refreshFilesList();
            super.onResume();
        }
    
        /**
         * Updates the list view to the current directory
         */
        protected void refreshFilesList() {
            // Clear the files ArrayList
            mFiles.clear();
    
            // Set the extension file filter
            ExtensionFilenameFilter filter = new ExtensionFilenameFilter(acceptedFileExtensions);
    
            // Get the files in the directory
            File[] files = mDirectory.listFiles(filter);
            if(files != null && files.length > 0) {
                for(File f : files) {
                    if(f.isHidden() && !mShowHiddenFiles) {
                        // Don't add the file
                        continue;
                    }
    
                    // Add the file the ArrayAdapter
                    mFiles.add(f);
                }
    
                Collections.sort(mFiles, new FileComparator());
            }
            mAdapter.notifyDataSetChanged();
        }
    
        @Override
        public void onBackPressed() {
            if(mDirectory.getParentFile() != null) {
                // Go to parent directory
                mDirectory = mDirectory.getParentFile();
                refreshFilesList();
                return;
            }
    
            super.onBackPressed();
        }
    
        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
            File newFile = (File)l.getItemAtPosition(position);
    
            if(newFile.isFile()) {
                // Set result
                Intent extra = new Intent();
                extra.putExtra(EXTRA_FILE_PATH, newFile.getAbsolutePath());
                setResult(RESULT_OK, extra);
                // Finish the activity
                finish();
            } else {
                mDirectory = newFile;
                // Update the files list
                refreshFilesList();
            }
    
            super.onListItemClick(l, v, position, id);
        }
    
        private class FilePickerListAdapter extends ArrayAdapter<File> {
    
            private List<File> mObjects;
    
            public FilePickerListAdapter(Context context, List<File> objects) {
                super(context, R.layout.file_picker_list_item, android.R.id.text1, objects);
                mObjects = objects;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
    
                View row = null;
    
                if(convertView == null) { 
                    LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    row = inflater.inflate(R.layout.file_picker_list_item, parent, false);
                } else {
                    row = convertView;
                }
    
                File object = mObjects.get(position);
    
                ImageView imageView = (ImageView)row.findViewById(R.id.file_picker_image);
                TextView textView = (TextView)row.findViewById(R.id.file_picker_text);
                // Set single line
                textView.setSingleLine(true);
    
                textView.setText(object.getName());
                if(object.isFile()) {
                    // Show the file icon
                    imageView.setImageResource(R.drawable.file);
                } else {
                    // Show the folder icon
                    imageView.setImageResource(R.drawable.folder);
                }
    
                return row;
            }
    
        }
    
        private class FileComparator implements Comparator<File> {
            public int compare(File f1, File f2) {
                if(f1 == f2) {
                    return 0;
                }
                if(f1.isDirectory() && f2.isFile()) {
                    // Show directories above files
                    return -1;
                }
                if(f1.isFile() && f2.isDirectory()) {
                    // Show files below directories
                    return 1;
                }
                // Sort the directories alphabetically
                return f1.getName().compareToIgnoreCase(f2.getName());
            }
        }
    
        private class ExtensionFilenameFilter implements FilenameFilter {
            private String[] mExtensions;
    
            public ExtensionFilenameFilter(String[] extensions) {
                super();
                mExtensions = extensions;
            }
    
            public boolean accept(File dir, String filename) {
                if(new File(dir, filename).isDirectory()) {
                    // Accept all directory names
                    return true;
                }
                if(mExtensions != null && mExtensions.length > 0) {
                    for(int i = 0; i < mExtensions.length; i++) {
                        if(filename.endsWith(mExtensions[i])) {
                            // The filename ends with the extension
                            return true;
                        }
                    }
                    // The filename did not match any of the extensions
                    return false;
                }
                // No extensions has been set. Accept all file extensions.
                return true;
            }
        }
    }
    

    MainActivity // This must be your default Activity, as MAIN in manifest

    public class MainActivity extends Activity implements OnClickListener {
    
        private static final int REQUEST_PICK_FILE = 1;
    
        private TextView mFilePathTextView;
        private Button mStartActivityButton;
        private File selectedFile;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            // Set the views
            mFilePathTextView = (TextView)findViewById(R.id.file_path_text_view);
            mStartActivityButton = (Button)findViewById(R.id.start_file_picker_button);
            mStartActivityButton.setOnClickListener(this);      
        }
    
        public void onClick(View v) {
            switch(v.getId()) {
            case R.id.start_file_picker_button:
                // Create a new Intent for the file picker activity
                Intent intent = new Intent(this, FilePickerActivity.class);
    
                // Set the initial directory to be the sdcard
                //intent.putExtra(FilePickerActivity.EXTRA_FILE_PATH, Environment.getExternalStorageDirectory());
    
                // Show hidden files
                //intent.putExtra(FilePickerActivity.EXTRA_SHOW_HIDDEN_FILES, true);
    
                // Only make .png files visible
                //ArrayList<String> extensions = new ArrayList<String>();
                //extensions.add(".png");
                //intent.putExtra(FilePickerActivity.EXTRA_ACCEPTED_FILE_EXTENSIONS, extensions);
    
                // Start the activity
                startActivityForResult(intent, REQUEST_PICK_FILE);
                break;
            
            case R.id.You_can_handle_more_onclick_events_from_here:
                //Do something
                break;
            }
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(resultCode == RESULT_OK) {
                switch(requestCode) {
                case REQUEST_PICK_FILE:
                    if(data.hasExtra(FilePickerActivity.EXTRA_FILE_PATH)) {
                        // Get the file path
                        selectedFile = new File(data.getStringExtra(FilePickerActivity.EXTRA_FILE_PATH));
                        // Set the file path text view
                        mFilePathTextView.setText(selectedFile.getPath());  
                        //Now you have your selected file, You can do your additional requirement with file.                
                    }
                }
            }
        }
    }
    

    Now Iam uploading images, You can use your own images.

    Image Name: file

    enter image description here

    Image Name: folder

    enter image description here

    and finally

    AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.myContactAdder.adder"
          android:versionCode="1"
          android:versionName="1.0">
          <uses-permission android:name="android.permission.READ_CONTACTS" />
          <uses-permission android:name="android.permission.WRITE_CONTACTS" />
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".FilePickerActivity"
                      android:label="@string/app_name">
            </activity>
            <activity android:name=".MainActivity"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <uses-sdk android:minSdkVersion="7" />
    
    </manifest> 
    

    Original references (now unavailable): Android file picker Activity and Creating simple file chooser.


    Edited after above ref not available.
    https://github.com/AndersKaloer/Android-File-Picker-Activity

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

Sidebar

Related Questions

Hi I want to know how I can working using c# application with yahoo
hi i am working on a window application using c#, i want to know
Hi i'm using Rotating Progress Bar in my Android Music Plyer Application....I'm not able
hi i am fresher now i am working android application...tell me how to create
Hi I am trying to deploy an application using webstart. I have a requirement
Hii all, I tried to test my application on the simulator and it fails.
Hi I am creating Spell Checker for my c# application. I am using using
hi i was working on a application developed in asp & c#.net, i want
Hi I am working on a Vb.Net application . I have a compose message
Hii I was coding for an application that shows the list of running process

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.