Android Scan SCard Card all pictures

Source: Internet
Author: User

    1. These days in order to scan all the pictures of SCard card is very tangled, I originally thought this is a very simple thing, but I found that I was wrong. There is no complete code on the web, just bits and pieces of code that can scan a single file. After today's code debugging passed, I think I need to share with you.
      1, because the mobile phone side of the scan, so it is best to open a thread. It is very important to have the scan done in a sub-thread, so start looking at this class now! This code can scan out all the files on the SCard card.


  1. Public class Getfilepaththread implements Runnable {

  2. Public String pathstring;
  3. Public List < String > listpath;
  4. Public Getfilepaththread(string path,List<string> List ) {
  5. This . pathstring=path;
  6. This . Listpath=list;
  7. }

  8. Public void Run (){

  9. File file = New File (pathstring) ;
  10. if (file. isdirectory ()){
  11. file fs[]=file. Listfiles ();
  12. if (fs!=null) {
  13. System . Out. println ("The number of files contained in the directory--->"+fs. length );
  14. if (fs. length >0){
  15.                          for ( int i= 0 I<, fs length I+ + ) Span style= "COLOR: #0000CC" >{
  16.                              if ( fs[ i] isfile ( ) {
  17.                                  listpath add ( fs[ i] getabsolutepath ( )
  18.                                   system Out println ( "file---->" + fs[ i getabsolutepath ( )
  19.                              } else if ( fs< Span style= "COLOR: #0000CC" >[ i] . isdirectory ( ) {
  20.                                   system Out println ( "directory---->" + fs[ i getabsolutepath ( ) + "/" )
  21. New Thread(NewGetfilepaththread(Fs[I].GetAbsolutePath()+"/",Listpath)).Start();
  22. //GetFilePath (Fs[i].getabsolutepath (), listpath);

  23. }
  24. }
  25. }
  26. }
  27. }
  28. }
  29. }


2. Scan the image files we need , of course, before you define it.
Private List list=new ArrayList ();



  1. StringBuffer Buffer = New StringBuffer ();
  2.                 for ( int I= 0; I<, list . size ( ; I+ + ) Span style= "COLOR: #0000CC" >{
  3.                      if ( list get ( i endswith ( ". jpg" ) {
  4. Buffer . Append (list. Get (i) . toString ()+"n");
  5. }
  6. }

3, remember to join about SCard card Read and Write permission, this is very important. As for the thread, I won't say much.
Summary: This code in small place tangled for a long time, really should not, the main problem is two, one is how to traverse the folder sub-file, the second, how to get the file path added to;
Hope these can be useful to everyone!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Scan SCard Card all pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.