Question

I am passing the url to get the images from the server e.g.

getBitmapFromURL("http://abc.xyz.in/logo.jpg");

But it is not returning anything. Saying that images are private. So my question is that is there anyway to pass the cookie to getBitmapFromURL() method. So that i can get the images. Or any other alternative is there? Thanks a lot.

Was it helpful?

Solution 2

I got my answer. I can do this by using following line:

connection.addRequestProperty("key", value);

OTHER TIPS

2014, if the answer is feasible to you please raise the answer and points

This should do the trick:

public static Bitmap getBitmapFromURL(String src) {
    try {
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
} 

Don't forget to add the internet permission and any other permission which is needed in your manifest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top