I'm trying to get an image stored on a php server from Android.

Asked 2 years ago, Updated 2 years ago, 31 views

I even realized that the photos stored in my phone were web-hosted and stored on the provided shared server. After that, I wanted to print out the image stored on the server again on my phone, but it didn't work as I thought, so I asked.

Then on the other hand, bring the image (file) stored on the other computer (server) and do not save it I'm trying to do it simply for viewing, but should I also consider this method as a download? The reason why I'm asking this question is

I searched for the search term in the context of "importing and loading images stored on the php server from Android" and found the source code, but I have not found a good example yet, so I am asking you this question.

For example, in this case, there are some image addresses that can be used and some that cannot be used ㅜㅜ If you have any examples to refer to, please share them with us.

private class load_image_task extends AsyncTask<String,Integer,Bitmap>{

        @Override
        protected Bitmap doInBackground(String... urls) {

            try{

                URL myFileUrl = new URL(urls[0]);
                HttpURLConnection conn = (HttpURLConnection)myFileUrl.openConnection();
                conn.setDoOutput(true);
                conn.connect();

                InputStream is = conn.getInputStream();
                bmImg = BitmapFactory.decodeStream(is);
            } } catch (MalformedURLException e) {
                e.printStackTrace();
            } } catch (IOException e) {
                e.printStackTrace();
            }
            return bmImg;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
            loadImage_view.setImageBitmap(bitmap);
        }
    }

android php

2022-09-22 20:38

1 Answers

Should I say that this is also a download because I don't want to bring images (files) stored on other computers (servers) and save them for viewing purposes?

The above question is correct to download.

There is a code similar to the code you posted below, so it would be helpful if you compare it.

And for the image that does not appear in the sample image, check what error occurred with the logcat and work in the direction of correcting or supplementing the code.

In addition, if the app is not at the sample level, there are many things to pay attention to showing images that are remotely located. Consider using an image load library that already covers these situations, such as performance, memory/disk cache, how to handle large images, displaying alternate images in case of errors, and handling image loading start/finish events.


2022-09-22 20:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.