2013-11-01 31 views
1

我是剛接觸android並且正在編寫一個應用程序,以編程方式將所有文檔文件複製到我的電腦中。我有我的文件夾列表(目前在一個列表視圖)。我只需要知道如何將每個文件複製到我的電腦中。一旦被複制,如何重新找回它們?我相信我需要在我的電腦中編寫一個服務器端程序,但有點關心從哪裏開始以及如何開始。以下是android代碼片段。將文件列表從Android傳輸到PC

public class DocsList extends Activity implements OnClickListener { 
CheckBox ChkSelectAll; 
ListView DocsList; 
Button Backup, Reset, GoBack; 
TextView textview; 
String[] FileNames; 
int k = 0; 
public List<String> myList; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    myList = new ArrayList<String>(); 
    setContentView(R.layout.docslist); 
    ChkSelectAll = (CheckBox)findViewById(R.id.SelectAllDocscheckBox); 
    DocsList  = (ListView)findViewById(R.id.DocsList); 
    Backup  = (Button)findViewById(R.id.BackupDocs); 
    Reset  = (Button)findViewById(R.id.ResetDocs); 
    GoBack  = (Button)findViewById(R.id.GoBackDocs); 

    String dir = Environment.getExternalStorageDirectory().toString(); 
    File f = new File(dir); 
    ArrayList<String> files = getListofDocs(f); 
    ArrayAdapter<String> PhoneAdptr = new ArrayAdapter<String>(this, android.R.layout.simple_selectable_list_item,files); 
    DocsList.setAdapter(PhoneAdptr); 
    boolean NetState = isNetworkConnected(this); 
    if (NetState == true) { 
     // Code yet to be written 
    } 
    else { 
     // Code yet to be written 
    } 
} 
private boolean isNetworkConnected(Context context) { 
     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
     NetworkInfo ni = cm.getActiveNetworkInfo(); 
     if (ni == null) { 
     // There are no active networks. 
     return false; 
     } else 
     return true; 
    } 

public ArrayList<String> getListofDocs(File parentdir) { 
    ArrayList<String> infiles = new ArrayList<String>(); 
    File[] files = parentdir.listFiles(); 
    if (files != null) { 
     for(File file : files) 
      if (file.isDirectory()) { 
       infiles.addAll(getListofDocs(file)); 
      } 
      else { 
       if (file.getName().endsWith("doc") || file.getName().endsWith("DOC") || 
         file.getName().endsWith("docx") || file.getName().endsWith("DOCX") || 
         file.getName().endsWith("htm") || file.getName().endsWith("HTM") || 
         file.getName().endsWith("html") || file.getName().endsWith("HTML") || 
         file.getName().endsWith("txt") || file.getName().endsWith("TXT") || 
         file.getName().endsWith("pdf") || file.getName().endsWith("PDF")) { 
        infiles.add(file.toString()); 
       } 
      } 
     } 

    return infiles; 
} 
@Override 
public void onClick(View v) { 
    if (v == GoBack) { 
     Intent Back = new Intent(DocsList.this, CloudStorage.class); 
     startActivity(Back); 
     finish(); 
    } 

} 

}

+1

沒有某種程序/服務器PC端接收數據,這不是一個簡單的任務。除非你在網絡上設置了某種類型的samba共享,在這種情況下,你可以將文件複製到那裏,然後從這兩個文件中訪問它們。 – LokiSinclair

回答

0

我剛纔所用的Dropbox的存儲我的文件。感謝你的幫助。儘管如此,我仍在努力進行檢索。

相關問題