0
Follow
0
View

How to display server-side images in Android client?

crazyrom 注册会员
2023-02-26 19:36

Part of the answer references GPT, GPT_Pro to better solve the problem
To display images on the server side to Android clients, you can use the following steps:

  1. On the server side, connect to the Android client using the HttpURLConnection class and set the related parameters:
    URL url = new URL(urlStr);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setConnectTimeout(5000);
    
  2. gets the server-side image stream and stores it in a Bitmap object:
    InputStream is = connection.getInputStream();
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    
  3. Displays the image object on the Android client:
    ImageView imageView = findViewById(R.id.image_view);
    imageView.setImageBitmap(bitmap);
    
  4. Closes the HttpURLConnection:
    if(connection != null){
     connection.disconnect();
    }
    
    These are the steps to display the image on the server side to the Android client, I believe you will be able to solve.
    If the answer is helpful, please accept it.

About the Author

Question Info

Publish Time
2023-02-26 19:36
Update Time
2023-02-26 19:36