Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. public class test extends Activity {
  2.  
  3.  
  4. TextView txtinfo;
  5. ProgressBar pbbar;
  6. EditText edtusername, edtpassword, edtservername, edtdir;
  7. Button btncopy;
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.test);
  12.  
  13. txtinfo = (TextView) findViewById(R.id.txtinfo);
  14. pbbar = (ProgressBar) findViewById(R.id.pbbar);
  15. pbbar.setVisibility(View.GONE);
  16.  
  17. edtpassword = (EditText) findViewById(R.id.edtpassword);
  18. edtdir = (EditText) findViewById(R.id.edtdir);
  19.  
  20. edtservername = (EditText) findViewById(R.id.edtservername);
  21. edtusername = (EditText) findViewById(R.id.edtusername);
  22.  
  23. edtusername.setText("test\test");
  24. edtpassword.setText("123");
  25. edtservername.setText("10.5.30.118/Pics_tablet/");
  26.  
  27. btncopy = (Button) findViewById(R.id.btncopy);
  28.  
  29. }
  30.  
  31. private class MyCopy extends AsyncTask<String, String, String> {
  32.  
  33. String z = "";
  34. String username = "", password = "", servername = "", filestocopy = "";
  35.  
  36. @Override
  37. protected void onPreExecute() {
  38.  
  39. pbbar.setVisibility(View.VISIBLE);
  40.  
  41. username = edtusername.getText().toString();
  42. password = edtpassword.getText().toString();
  43. servername = "smb://" + edtservername.getText().toString();
  44. filestocopy = edtdir.getText().toString();
  45. }
  46.  
  47. @Override
  48. protected void onPostExecute(String r) {
  49. txtinfo.setText(r);
  50. pbbar.setVisibility(View.GONE);
  51. }
  52.  
  53. @Override
  54. protected String doInBackground(String... params) {
  55.  
  56. File file = new File(filestocopy);
  57. String filename = file.getName();
  58.  
  59. NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(
  60. servername, username, password);
  61.  
  62. try {
  63.  
  64. SmbFile sfile = new SmbFile(servername + "/" + filename, auth1);
  65. if (!sfile.exists())
  66. sfile.createNewFile();
  67. sfile.connect();
  68.  
  69. InputStream in = new FileInputStream(file);
  70.  
  71. SmbFileOutputStream sfos = new SmbFileOutputStream(sfile);
  72.  
  73. in.close();
  74. sfos.close();
  75.  
  76. z = "File copied successfully";
  77. } catch (Exception ex) {
  78.  
  79. z = z + " " + ex.getMessage().toString();
  80. }
  81.  
  82. return z;
  83. }
  84. }
  85.  
  86. public void btn_aprove (View view)
  87. {
  88.  
  89. UpdatePro updatePro = new UpdatePro();
  90. updatePro.execute("");
  91. MyCopy mycopy = new MyCopy();
  92. mycopy.execute("");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement