Get the absolute path to the picture in the phone and differentiate the path under each folder: The name of the folder that holds the absolute path to the picture, and the list entity class that holds the absolute path as follows:
1 Importjava.util.ArrayList;2 Importjava.util.List;3 4 Public classImagePath {5 PrivateString Pakagepath;6 PrivateList<string> listpth =NewArraylist<string>();7 8 9 PublicString Getpakagepath () {Ten returnPakagepath; One } A Public voidSetpakagepath (String pakagepath) { - This. Pakagepath =Pakagepath; - } the PublicList<string>getlistpth () { - returnlistpth; - } - Public voidSetlistpth (list<string>listpth) { + This. listpth =listpth; - } + A}Separate the absolute path of the picture in the phone by the package name:
1 Privatecontentresolver Contentresolver;2 Privatebutton button;3 PrivateURI Uri;4 PrivateList<imagepath>imagepaths;5 PrivateList<imagepath>Getimgpath () {6Imagepaths =NewArraylist<imagepath>();7Contentresolver = This. Getcontentresolver ();8URI =Media.external_content_uri;9cursor cursor = contentresolver.query (URI,NULL,NULL,NULL,NULL);TenSet<string> set =NewTreeset<string>(); OneList<string> Lspsth =NewArraylist<string>(); A while(Cursor.movetonext ()) { - //Get absolute path -String Path =cursor.getstring (Cursor.getcolumnindex (Media.data)); the //add an absolute path to the list - lspsth.add (path); - //Get package name -String Pakagename =cursor.getstring (Cursor.getcolumnindex (Media.bucket_display_name)); + //Add the package name to the set - Set.add (pakagename); + } A //Set Conversion Array atString[] Str =set.toarray (Newstring[set.size ()]); - //loop array with package name - for(inti = 0; i < str.length; i++) { - //creates a ImagePath object that stores all absolute paths (including package names) under a package -ImagePath ImagePath =NewImagePath (); - //creates a ImagePath object that stores all absolute paths under a package (without the package name) inList<string> Listpath =NewArraylist<string>(); - //depositing the first package name in the STR array into a ImagePath object to Imagepath.setpakagepath (Str[i]); + //all absolute paths in the loop lspsth - for(intk = 0; K < Lspsth.size (); k++) { the //Determine if Lspathget (k) is the absolute path under which the absolute path is currently under the Str[i] Package name * if(Getpakagenamebypath (Lspsth.get (k)). Equals (Str[i])) { $ //if it is deposited in ListpathPanax Notoginseng Listpath.add (Lspsth.get (k)); - } the } + //ImagePath the distinguished game path into the object of the package name to be used A imagepath.setlistpth (listpath); the //save the object in the Imagepaths collection + Imagepaths.add (imagePath); - } $ returnimagepaths; $}
1 /**2 * The package name of the path is obtained according to the path3 * @paramPath4 * @return5 */6 Publicstring Getpakagenamebypath (string path) {7String Pkgname =NULL;8 if(Path.length () >0){9string[] str = path.split ("/");TenPkgname = Str[str.length-2]; One } A returnPkgname; - } -
Not finished ....
Android Action Album