Android file manager usage details

I haven't written anything for a long time. Since so and so can't use the file manager, here's a brief introduction. At the same time, I write a demon. I refer to the code written by others on the Internet. I also study and research myself@ H_ 419_ 1@

First of all, the so-called file manager looks like a list. There are folders or files in the list. First write out the layout. I want to display the path of the file on the top left and the number of files under the path on the right. In fact, it is still a problem of traversing the file and then displaying it in the list. The following is the listview, which is used to display the file list. The following is the effect picture of operation: @ h_ 419_ 1@

@H_ 419_ 1@@H_ 419_ 1@

The layout file of the main interface is as follows: @ h_ 419_ 1@

First, call a method in the oncreate method to obtain the ID: @ h in the layout file_ 419_ 1@

Add APK permission after initview, 777 indicates that it is readable, writable and operable@ H_ 419_ 1@

How to modify root permissions: @ h_ 419_ 1@

After that, we need to get all the data under the root directory, and then set it to our listview to display it@ H_ 419_ 1@

First, get whether it is the current root directory, and then set the path of the file to the view we want to display@ H_ 419_ 1@

Then use an ArrayList to load all the files or folders in our directory@ H_ 419_ 1@

First of all, we need to load the parent class of this folder into our list, then we can get all the subfiles under this folder and put them in the list, and then call Adapter to display them. Now that we have talked about the adapter, let's take a look at the adapter@ H_ 419_ 1@

@H_ 419_ 1@

Look at the layout file of adapter: @ h_ 419_ 1@

The item item in the list is displayed in 2 lines, and the file name @ h is displayed in the upper line_ 419_ 1@

The following line shows the file size, file type and file modification time respectively@ H_ 419_ 1@

We can use file = (file) getitem (position); If the file of the item item is in the first and no longer in the root directory, we will display the first parent file as "return to the previous level", and the next line will be hidden@ H_ 419_ 1@

If it is not the first location, you can get a series of information about this file@ H_ 419_ 1@

First set string filename = file. Getname(); Get the file name and display it@ H_ 419_ 1@

If the file is a folder, the size of the file is displayed as "folder", and the type and modification time are hidden@ H_ 419_ 1@

If it is not a folder, you can get the length of the file long filesize = file. Length()@ H_ 419_ 1@

Displays the size of the file according to a specific length, B, KB, MB, GB, etc@ H_ 419_ 1@

Then get the file type. The string after the last "." is the file type@ H_ 419_ 1@

Through viewholder.data.settext (New simpledateformat ("yyyy / mm / DD HH: mm"). Format (file. Lastmodified()); Set the last modification time of the file@ H_ 419_ 1@

Then you can set the click event of each item item as follows: @ h_ 419_ 1@

If the file cannot be read, a dialog box will pop up showing "insufficient permission"@ H_ 419_ 1@

If it is a folder, the method of displaying all files at once is called: initdata (file); Pass this folder as a parameter@ H_ 419_ 1@

If it is a file, you can call the method of opening the file to open the file@ H_ 419_ 1@

How do I open a file@ H_ 419_ 1@

You can find different file types according to the suffix names of different files: @ h_ 419_ 1@

You can use a two-dimensional array to encapsulate some common file types. As follows: @ h_ 419_ 1@

They correspond to the suffix name and the corresponding file type@ H_ 419_ 1@

We can get the mimeType type of the file according to the suffix of the file: @ h_ 419_ 1@

Traverse the suffix first. If found, find the corresponding type and return it@ H_ 419_ 1@

When you get the type, you can open this file@ H_ 419_ 1@

Use this intent. Setdataandtype (URI. Fromfile (file), type); Open sets the type of file to open@ H_ 419_ 1@

If the type is * / * all selectable applications will pop up@ H_ 419_ 1@

Here, a simple file manager takes shape@ H_ 419_ 1@

Source code: @ h_ 419_ 1@

@H_ 419_ 1@

Finally, the dimension in the layout file is compiled into the jar package. Children's shoes without jar package can be changed to their own defined size@ H_ 419_ 1@

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips@ H_ 419_ 1@

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
分享
二维码
< <上一篇
下一篇>>