Button btn;
Runnable mUpdateUITimerTask;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
public void onClick(View v) {
(new UpDateOperation()).execute("");
}
public void uploadFile(File fileName) {
FTPClient client = new FTPClient();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
client.connect(FTP_HOST, 21);
client.login(FTP_USER, FTP_PASS);
if (client.isAuthenticated() == true) {
Log.d("hello", "world" + fileName.getName());
client.setType(FTPClient.TYPE_BINARY);
client.upload(fileName);
}
} catch (Exception e) {
e.printStackTrace();
try {
client.disconnect(true);
Log.d("chal", "ja");
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public class UpDateOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
uploadFile(null);
return "hello";
}
}
}
答案 0 :(得分:1)
你应该将实际文件作为第一个参数传递给AsyncTask(比如,或者只是在uploadFile方法中创建它并传递带有文件名的String