Code Monkey home page Code Monkey logo

afilechooser's Introduction

aFileChooser - Android File Chooser

aFileChooser is an Android Library Project that simplifies the process of presenting a file chooser.

Intents provide the ability to hook into third-party app components for content selection. This works well for media files, but if you want users to be able to select any file, they must have an existing File Explorer app installed. Because many Android devices don't have stock File Explorers, the developer must often instruct the user to install one, or build one, themselves. aFileChooser solves this issue.

Features:

  • Full file explorer
  • Simplify GET_CONTENT Intent creation
  • Easily convert a Uri into a File
  • Determine MIME data types
  • Follows Android conventions (Fragments, Loaders, Intents, etc.)

screenshot-1 screenshot-2

Installation

Add aFileChooser to your project as an Android Library Project.

Add FileChooserActivity to your project's AndroidManifest.xml file with a fully-qualified name. The label and icon set here will be shown in the "Intent Chooser" dialog.

Important FileChooserActivity must have the <intent-filter> set as follows:

<activity
    android:name="com.ipaulpro.afilechooser.FileChooserActivity"
    android:icon="@drawable/ic_chooser"
    android:label="@string/chooser_label" >
    <intent-filter>
        <action android:name="android.intent.action.GET_CONTENT" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.OPENABLE" />

        <data android:mimeType="*/*" />
    </intent-filter>
</activity>

Usage

Use startActivityForResult(Intent, int) to launch the "Intent Chooser" dialog (shown below), or FileChooserActivity directly. FileChooserActivity returns the Uri of the file selected as the Intent data in onActivityResult(int, int, Intent).

private static final int REQUEST_CHOOSER = 1234;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent getContentIntent = FileUtils.createGetContentIntent();
    Intent intent = Intent.createChooser(getContentIntent, "Select a file");
    startActivityForResult(intent, REQUEST_CHOOSER);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    	case REQUEST_CHOOSER:	
        	if (resultCode == RESULT_OK) {	
            	final Uri uri = data.getData();
            	File file = FileUtils.getFile(uri);
        	}
    }
}

A more robust example can be found in the aFileChooserExample folder.

Note The FileUtils class provides a helper method to construct an ACTION_GET_CONTENT Intent (FileUtils.createGetContentIntent()). It also contains a method to convert a Uri into a File (FileUtils.getFile(Uri)).

Credits

Developed by Paul Burke (iPaulPro) - paulburke.co

Translations by Thomas Taschauer (TomTasche) - tomtasche.at

License

Copyright (C) 2011 - 2013 Paul Burke

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

---

FileUtils.java, MimeTypeParser.java and MimeTypes.java:

Copyright (C) 2007-2008 OpenIntents.org

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

afilechooser's People

Contributors

booknara avatar brenouchoa avatar holoceo avatar ipaulpro avatar ruiaraujo avatar tomtasche avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.