Skip to content Skip to sidebar Skip to footer

Android Bitmapfactory.decodestream(...) Doesn't Load Https Url On Emulator

App doesn't load an Image from an HTTPS URL when run on the emulator. Sample code: URL url = new URL('https://someserver.com/photo.jpg'); mImageView.setImageBitmap(BitmapFactory.d

Solution 1:

Use below code for display image in imageview from url.

ImageViewmImageView= (ImageView)findViewById(R.id.mImageView1);

URLurl=newURL(address);
InputStreamcontent= (InputStream)url.getContent();
Drawabled= Drawable.createFromStream(content , "src"); 
mImageView.setImageDrawable(d);

And also use below code for that.

try {
    URLurl=newURL(imageUrl);
    HttpGethttpRequest=null;

    httpRequest = newHttpGet(url.toURI());

    HttpClienthttpclient=newDefaultHttpClient();
    HttpResponseresponse= (HttpResponse) httpclient.execute(httpRequest);

    HttpEntityentity= response.getEntity();
    BufferedHttpEntityb_entity=newBufferedHttpEntity(entity);
    InputStreaminput= b_entity.getContent();

    Bitmapbitmap= BitmapFactory.decodeStream(input);

    ImageViewmImageView= (ImageView) findViewById(R.id.mImageView);
    mImageView.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
    Log.e("log", "bad url", t);
} catch (IOException e) {
    Log.e("log", "io error", t);
}

Solution 2:

Is this a trusted https site? If not you will have a problem with the connection.

Take a look at this...

http://droidos-coding.blogspot.com/2012/03/android-trusting-all-https-self-signed.html

Solution 3:

Try this code:

imageView.setImageBitmap(LoadImageFromWebOperations(url));

private Bitmap LoadImageFromWebOperations(String url){
           try{
             Stringencodedurl= url.replace(" ", "%20");
             InputStreamis= (InputStream) newURL(encodedurl).getContent();
             Bitmapd= BitmapFactory.decodeStream(is);
             return d;
           }catch (Exception e) {
            e.printStackTrace();
//          System.out.println("Exc="+e);returnnull;
           }
         }

And pls make sure u have added internet permission in your manifest file. This will help u to do so.

Post a Comment for "Android Bitmapfactory.decodestream(...) Doesn't Load Https Url On Emulator"