2

エミュレーターでアプリを実行すると、HTTPS URL から画像が読み込まれません。

サンプルコード:

URL url = new URL("https://someserver.com/photo.jpg");
mImageView.setImageBitmap(BitmapFactory.decodeStream(url.openStream()));

実際のデバイスで実行すると、画像は問題なく読み込まれます。また、HTTPS ではなく HTTP 経由でアクセスされた場合、エミュレーターは画像を読み込みます。

私は何か間違ったことをしていますか、それとも既知の問題ですか?

4

3 に答える 3

7

URLからimageviewに画像を表示するには、以下のコードを使用します。

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

URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
mImageView.setImageDrawable(d);

また、そのために以下のコードを使用します。

try {
    URL url = new URL(imageUrl);
    HttpGet httpRequest = null;

    httpRequest = new HttpGet(url.toURI());

    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

    HttpEntity entity = response.getEntity();
    BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
    InputStream input = b_entity.getContent();

    Bitmap bitmap = BitmapFactory.decodeStream(input);

    ImageView mImageView = (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);
}
于 2012-07-07T06:54:45.640 に答える
1

これは信頼できる https サイトですか? そうでない場合は、接続に問題があります。

これを見てください...

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

于 2012-07-07T06:40:24.727 に答える
0

このコードを試してください:

imageView.setImageBitmap(LoadImageFromWebOperations(url));

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

マニフェスト ファイルにインターネット アクセス許可が追加されていることを確認してください。これは、そうするのに役立ちます。

于 2012-07-07T06:53:43.470 に答える