For a long time did not write the article, originally wanted to write something, a long, feel don't want to write, no use, to time, and do not know where to find or how to solve.
There is a saying that good, good memory than bad writing.
I want to be good at summing up, in a timely manner, the amount of ... ........
Well, the nonsense is not much, get into the chase.
Do a little thing about the music player, need to read the file (the problem comes ...) ), I found the Android 4.4 version about level two external memory read and write as follows:
I write the software there is such a problem, can run normally, sdcard in the. mp3 file, no error, but in 4.4 is the reality does not come out of the list of content, 2.2 can be displayed.
So I hold the mentality of trying to join the following permissions.
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
I didn't think it was successful. There is a picture of the truth:
Filter files with the FilenameFilter excuse accept (file file, String name) method, there is no writing about it.
So it seems that the above permission, not only for writing, but also to read, do not know that it is right ah, to a great God.
The code is as follows:
Mainactivity.java
public class Mainactivity extends Listactivity {//public final static String Path = "/sdcard/"; Arrayadapter<string> arrayadapter = null; List<string> stringlist; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); stringlist = new arraylist<string> (); Showmusiclist (); arrayadapter = new Arrayadapter<string> (mainactivity.this,android. R.layout.simple_list_item_1, stringlist); Setlistadapter (Arrayadapter);} public void Showmusiclist () {file[] files = null; File MyFile = Environment.getexternalstoragedirectory ();//Get sdcard path File File = new file (Myfile.getabsolutepath ()); Files = file.listfiles (new Filename ()); Filter file if (Files! = null) {for (int i = 0; i < files.length; i++) {File T_file = Files[i];stringlist.add (T_file.getname ( ));}}} Class Filename implements FilenameFilter {@Overridepublic Boolean accept (file file, String name) {//TODO auto-generated m Ethod Stubreturn name.endswith (". mp3");}}}
.
A little discovery about Android 2.2 with 4.4 of files read