我是 android 新手,正在编写一个应用程序以编程方式将所有文档文件复制到我的 PC 中。我有文件夹中的文件列表(当前在列表视图中)。我只需要知道如何将每个文件复制到我的电脑中。复制后如何找回?我确信我也需要在我的 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();
}
}
}