Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class test extends Activity {
- TextView txtinfo;
- ProgressBar pbbar;
- EditText edtusername, edtpassword, edtservername, edtdir;
- Button btncopy;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.test);
- txtinfo = (TextView) findViewById(R.id.txtinfo);
- pbbar = (ProgressBar) findViewById(R.id.pbbar);
- pbbar.setVisibility(View.GONE);
- edtpassword = (EditText) findViewById(R.id.edtpassword);
- edtdir = (EditText) findViewById(R.id.edtdir);
- edtservername = (EditText) findViewById(R.id.edtservername);
- edtusername = (EditText) findViewById(R.id.edtusername);
- edtusername.setText("test\test");
- edtpassword.setText("123");
- edtservername.setText("10.5.30.118/Pics_tablet/");
- btncopy = (Button) findViewById(R.id.btncopy);
- }
- private class MyCopy extends AsyncTask<String, String, String> {
- String z = "";
- String username = "", password = "", servername = "", filestocopy = "";
- @Override
- protected void onPreExecute() {
- pbbar.setVisibility(View.VISIBLE);
- username = edtusername.getText().toString();
- password = edtpassword.getText().toString();
- servername = "smb://" + edtservername.getText().toString();
- filestocopy = edtdir.getText().toString();
- }
- @Override
- protected void onPostExecute(String r) {
- txtinfo.setText(r);
- pbbar.setVisibility(View.GONE);
- }
- @Override
- protected String doInBackground(String... params) {
- File file = new File(filestocopy);
- String filename = file.getName();
- NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(
- servername, username, password);
- try {
- SmbFile sfile = new SmbFile(servername + "/" + filename, auth1);
- if (!sfile.exists())
- sfile.createNewFile();
- sfile.connect();
- InputStream in = new FileInputStream(file);
- SmbFileOutputStream sfos = new SmbFileOutputStream(sfile);
- in.close();
- sfos.close();
- z = "File copied successfully";
- } catch (Exception ex) {
- z = z + " " + ex.getMessage().toString();
- }
- return z;
- }
- }
- public void btn_aprove (View view)
- {
- UpdatePro updatePro = new UpdatePro();
- updatePro.execute("");
- MyCopy mycopy = new MyCopy();
- mycopy.execute("");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement