I want to set ImageView bitmap from our network drive. But i getting Unable to connect to server: Unable to log in to server (PASS): 141.11.11.247 error.
Here is my download ant setBitmap code for this :
public class ResimCek implements Runnable {
int resimID = 0;
public ResimCek(int parcaID) {
// store parameter for later user
resimID = parcaID;
}
public void run() {
try {
ImageView resim = (ImageView) findViewById(resimID);
Bitmap bitmap = BitmapFactory
.decodeStream((InputStream) new URL(
"file://141.11.11.247/foto_metod/Parca/"
+ Integer.toString(resimID) + ".jpg")
.getContent());
resim.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Here is my last code :
public class ResimCek implements Runnable {
int resimID = 0;
public ResimCek(int parcaID) {
// store parameter for later user
resimID = parcaID;
}
public void run() {
int resID = getResources().getIdentifier(Integer.toString(resimID) , "tag", getPackageName());
ImageView resim = (ImageView) findViewById(resID);
Drawable image = ImageOperations(getBaseContext(),"http://141.11.11.206/parca/" + Integer.toString(resimID) + ".jpg" ,"I" + Integer.toString(resimID) + ".jpg");
// ******************************************************
resim.setImageDrawable(image); // I GOT THE ERROR HERE!!!
}
}
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(new URL(url).openConnection().getInputStream(),saveFilename);
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
Thanks for your help.
may be you forgot to declare internet permission in your manifest file, check it please.