复杂化: - /这里是更好的解决方案:
private class NetworkUsers extends AsyncTask {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
// your code, thats runs before "doInBackground" action
}
@Override
protected void onPostExecute(String result) {
// your code, thats runs after "doInBackground" action
if(result != null){
// handle "result" String
} else {
}
}
@Override
protected String doInBackground(String... params) {
SmbFile[] domains = null;
String result = null;
String url = params[0];
SmbFile path = null;
try {
path = new SmbFile(url);
try {
if(path.exists()){
result = ""; // set result variable to empty
domains = (new SmbFile(url)).listFiles();
for (int i = 0; i < domains.length; i++) {
// here you can add custom validations
// for example if(domains[i].isHidden()){} | example if(domains[i].canRead()){} , etc.
result += domains[i].toString() + "\n";
}
}
} catch (SmbException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return result;
}
}
如何使用:
(new NetworkUsers()).execute("smb://");
名单设备的内容:
列表根上所有的网络设备
(new NetworkUsers()).execute("smb://my-device/shared/"); //my-device is the network device name