문제

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.

도움이 되었습니까?

해결책 2

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

connection.addRequestProperty("key", value);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top