Search on AEQ-WEB

AEQ-WEB | Blog

Android Image Download from PHP Java Code

Android Image Download

On this page, we will show you how to download an image from a PHP file with Android using the HTTP client. At the bottom of the app there is a button, which starts the task for the download process. After a successful download in the task the photo is loaded into the ImageView. After the download, the result of the download is displayed in the TextView.

Android Version API Version
4.0.3 15

PHP Server

The PHP script provides the data for the app. The photo is loaded directly from the php file and not from a path with the image file. This has the advantage that not every image has its own file. With the GET-parameters, the picture output can be controlled. In addition, the script can be modified so that the image is displayed only after authorization. The PHP code used here has three images of which it randomly outputs one. This example is also available on our testserver and is compatible with the app.

Image Server
HTTP_Image Source

MainActivity: This section must be copied to MainActivity.

public class MainActivity extends AppCompatActivity {

    TextView txt;
    boolean download_ok;
    protected void onCreate(Bundle savedInstanceState) {
        txt = (TextView)findViewById(;
        Button button= (Button) findViewById(;
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                new DownloadImageFromInternet((ImageView) findViewById(
    private class DownloadImageFromInternet extends AsyncTask {
        ImageView imageView;

        public DownloadImageFromInternet(ImageView imageView) {
            this.imageView = imageView;
            txt.setText("Try to download image....");

        protected Bitmap doInBackground(String... urls) {
            String imageURL = urls[0];
            Bitmap d_image = null;
            try {
                InputStream in = new;
                d_image = BitmapFactory.decodeStream(in);
                download_ok = true;
            } catch (Exception e) {
                download_ok = false;
            return d_image;

        protected void onPostExecute(Bitmap result) {

        void txt_update (){
            if(download_ok == true) {
                txt.setText("Image was successfully downloaded");
            }else {
                txt.setText("Image could not be downloaded");


Manifest: This line must copied to the manifest and will allow access to the Internet.

<uses-permission android:name="android.permission.INTERNET" />

Info: This page was automatically translated and may contain errors
Android Image Upload

On this page we show you how to send an image via an Android APP with HTTP-POST to a PHP server. The source code is available here.

Alex @ AEQ-WEB
Android GSM/LTE Status

On this page we show you how to get the status of the mobile network with android. The source code and the APK file are available here

Alex @ AEQ-WEB