I ran into the same problem that the link ran into and did not respond to it properly. I am using the code below.
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
String url = "smb://DHARMU-PC/" + sharedFolder + "/new plugin.txt";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null);
SmbFile sfile = new SmbFile(url,auth);
if (sfile!=null)
{
Toast.makeText(Main2Activity.this,"Not", Toast.LENGTH_SHORT).show();
sfile.getInputStream();
}
else
{
Toast.makeText(Main2Activity.this, "Succsess", Toast.LENGTH_SHORT).show();
}
} catch (MalformedURLException e) {
Toast.makeText(Main2Activity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
When I comment on the application sfile.getInputStream (); works fine, but with the getinputstream application without any exceptions in the catch catch block. Since the above question did not answer, I again posed this question.
change
Now I tried using the Async task
class CopySMBFile extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... f_url) {
try {
String fileContent = "This is a test file";
try{
String user = "myusername:mypassword";
System.out.println("User: " + user);
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
String path = "smb://192.168.1.12/k/temp/A.txt";
System.out.println("Path: " +path);
SmbFile sFile = new SmbFile(path, auth);
SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
sfos.write(fileContent.getBytes());
System.out.println("Finished attempt to write file");
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
Log.e("Connected", e.getMessage());
}
return null;
}
With Async Task, SmbFileOutputStream now works, but still shows Fatal Error with getinputstream.
Edit
Found the reason Appcrash is a networkmainthread exception. Now a kind guide for solving it.
source
share