2013-11-01 33 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的存储我的文件。感谢你的帮助。尽管如此,我仍在努力进行检索。

相关问题