Detailed explanation and example code of Android file selector

This article explains the use of Android file selector. In fact, it is to obtain the path of the file or folder selected by the user in the SD card, which is much like the openfiledialog control in c#.

The implementation process of this example is very simple, which can make you quickly familiar with Android file selector and improve development efficiency.

An example of file selector has been seen on the Internet, and many people have seen it. This example is modified based on it, but it is easier to understand and more efficient. In addition, this example has its own characteristics:

1. Listens to the event that the user presses the back key to return to the previous directory.

2. Special treatment is made for different file types (file vs folder, target file vs other files).

Knowledge point 1. Use of file class

The main functions of the file selector are: browsing files \ folders, file types, etc; Are implemented through the java file class.

Knowledge point 2. Description of calling method

It uses the startactivityforresult() method to initiate the call and the onactivityresult() method to receive the callback information.

First paste the renderings as follows:

There's nothing else to say. Let's take a look at the code comments. It's very simple.

FileChooserActivity. Java implements the class selected by the file.

Java code

The interface of this example is a little crude, but you can improve it and add other functions on this basis. Download address of this example code:

http://download.csdn.net/detail/qinjuning/4825392 。

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>