Simplified Coding

  • About
  • Contact Us
  • Advertise
  • Privacy Policy
You are here: Home / Android Application Development / Android Advance / Android Download Image from Server using PHP and MySQL

Android Download Image from Server using PHP and MySQL

September 4, 2015 by Belal Khan 87 Comments

In the last post we uploaded our image from gallery to our MySQL Database. In this post we will see how we can fetch those uploaded images. If you have not read the last tutorial, then before going through this Android Download Image from Server tutorial you should first check the last tutorial.

Android Upload Image to Server Using PHP MySQL

Android Download Image from MySQL Database

  • First go to your hosting account. For this tutorial I am using free hosting account by hostinger.
  • In last tutorial we created two scripts. One for database connection and other one for storing image to database. Now we need to create one more php script that will fetch the uploaded image.
  • Create a new PHP file. I am creating getImage.php
  • Copy the following code

android download image
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
 
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['id'];
$sql = "select * from images where id = '$id'";
require_once('dbConnect.php');
$r = mysqli_query($con,$sql);
$result = mysqli_fetch_array($r);
header('content-type: image/jpeg');
echo base64_decode($result['image']);
mysqli_close($con);
}else{
echo "Error";
}

Explanation of Code:

  • As you can see we are receiving the id with Http Get Request. Then we are fetching the particular image string using sql query. Now set content-type as image or jpeg using header function. And finally we just written an echo statement with base64_decode function. This will echo the image string in image format.

Now go ahead:

  • Upload this file to your hosting account.
  • Note down the URL for this php script. In my case the URL is – http://simplifiedcoding.16mb.com/ImageUpload/getImage.php

Creating Android Download Image Activity

  • Now we will create a new Activity. In this activity user will give the image id and we will fetch the image by id.
  • Right click on layout-> New -> Activity -> Blank Activity (I created ViewImage)
  • Now a layout xml file and a java file is created (ViewImage.java and activity_view_image.xml)
  • Come to the layout file. We need to create the following layout.
android download image

android download image

  • Use the following code for creating the above layout

android download image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="net.simplifiedcoding.imageuploadsample.ViewImage">
 
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/editTextId" />
 
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Get Image"
            android:id="@+id/buttonGetImage" />
 
    </LinearLayout>
 
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageViewShow" />
 
 
</LinearLayout>

Explanation:

  • We have created a horizontal linear layout inside a vertical linear layout. In horizontal part we have an EditText and a Button. In EditText user is supposed to enter the image id. After entering image id user will press the button and then we will show the fetched image in the ImageView we created.

Go Ahead:

  • At last tutorial in our main layout we created a View Image button. Now we will add functionality to this button.
  • So come to your MainActivity.java class
  • See this code this is the updated code. You need to update your code as shown here.

Android Download Image
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package net.simplifiedcoding.imageuploadsample;
 
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
 
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
 
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 
    public static final String UPLOAD_URL = "http://simplifiedcoding.16mb.com/ImageUpload/upload.php";
    public static final String UPLOAD_KEY = "image";
    public static final String TAG = "MY MESSAGE";
 
    private int PICK_IMAGE_REQUEST = 1;
 
    private Button buttonChoose;
    private Button buttonUpload;
    private Button buttonView;
 
    private ImageView imageView;
 
    private Bitmap bitmap;
 
    private Uri filePath;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        buttonChoose = (Button) findViewById(R.id.buttonChoose);
        buttonUpload = (Button) findViewById(R.id.buttonUpload);
        buttonView = (Button) findViewById(R.id.buttonViewImage);
 
        imageView = (ImageView) findViewById(R.id.imageView);
 
        buttonChoose.setOnClickListener(this);
        buttonUpload.setOnClickListener(this);
        buttonView.setOnClickListener(this);
    }
 
    private void showFileChooser() {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
 
        if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
 
            filePath = data.getData();
            try {
                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                imageView.setImageBitmap(bitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
    public String getStringImage(Bitmap bmp){
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] imageBytes = baos.toByteArray();
        String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
        return encodedImage;
    }
 
    private void uploadImage(){
        class UploadImage extends AsyncTask<Bitmap,Void,String>{
 
            ProgressDialog loading;
            RequestHandler rh = new RequestHandler();
 
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(MainActivity.this, "Uploading...", null,true,true);
            }
 
            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
            }
 
            @Override
            protected String doInBackground(Bitmap... params) {
                Bitmap bitmap = params[0];
                String uploadImage = getStringImage(bitmap);
 
                HashMap<String,String> data = new HashMap<>();
                data.put(UPLOAD_KEY, uploadImage);
 
                String result = rh.sendPostRequest(UPLOAD_URL,data);
 
                return result;
            }
        }
 
        UploadImage ui = new UploadImage();
        ui.execute(bitmap);
    }
 
    @Override
    public void onClick(View v) {
        if (v == buttonChoose) {
            showFileChooser();
        }
        if(v == buttonUpload){
            uploadImage();
        }
        if(v == buttonView){
            viewImage();
        }
    }
 
    private void viewImage() {
        startActivity(new Intent(this, ViewImage.class));
    }
}

Explanation:

  • This part is same as the last part. We just created a new button to open ImageView activity. We are opening the ImageView activity by using Intent.

Go Ahead:

  • After updating your MainActivity.java file, when we will tap the view image button, our ViewImage activity will open.
  • Now finally come to your ViewImage.java file and write the following code

Android Download Image
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package net.simplifiedcoding.imageuploadsample;
 
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
 
public class ViewImage extends AppCompatActivity implements View.OnClickListener{
 
    private EditText editTextId;
    private Button buttonGetImage;
    private ImageView imageView;
 
    private RequestHandler requestHandler;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_image);
 
        editTextId = (EditText) findViewById(R.id.editTextId);
        buttonGetImage = (Button) findViewById(R.id.buttonGetImage);
        imageView = (ImageView) findViewById(R.id.imageViewShow);
 
        requestHandler = new RequestHandler();
 
        buttonGetImage.setOnClickListener(this);
    }
 
    @Override
    public void onClick(View v) {
        getImage();
    }
}

Explanation: 

  • We declared the instances of our EditText, ImageView, Button and RequestHandler. In onCreate method we initialized our instances and for button we set the onClickListener which is the current class itself.
  • In onClick method we wrote a method getImage(). This method will fetch the respective image according to the id given.
  • Now we need to create the getImage method. See the following code.

getImage()

Android Download Image
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
private void getImage() {
        String id = editTextId.getText().toString().trim();
        class GetImage extends AsyncTask<String,Void,Bitmap>{
            ProgressDialog loading;
 
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewImage.this, "Uploading...", null,true,true);
            }
 
            @Override
            protected void onPostExecute(Bitmap b) {
                super.onPostExecute(b);
                loading.dismiss();
                imageView.setImageBitmap(b);
            }
 
            @Override
            protected Bitmap doInBackground(String... params) {
                String id = params[0];
                String add = "http://simplifiedcoding.16mb.com/ImageUpload/getImage.php?id="+id;
                URL url = null;
                Bitmap image = null;
                try {
                    url = new URL(add);
                    image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return image;
            }
        }
 
        GetImage gi = new GetImage();
        gi.execute(id);
    }

Final Code for ViewImage.java 

Android Download Image
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package net.simplifiedcoding.imageuploadsample;
 
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
 
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
 
public class ViewImage extends AppCompatActivity implements View.OnClickListener{
 
    private EditText editTextId;
    private Button buttonGetImage;
    private ImageView imageView;
 
    private RequestHandler requestHandler;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_image);
 
        editTextId = (EditText) findViewById(R.id.editTextId);
        buttonGetImage = (Button) findViewById(R.id.buttonGetImage);
        imageView = (ImageView) findViewById(R.id.imageViewShow);
 
        requestHandler = new RequestHandler();
 
        buttonGetImage.setOnClickListener(this);
    }
 
 
    private void getImage() {
        String id = editTextId.getText().toString().trim();
        class GetImage extends AsyncTask<String,Void,Bitmap>{
            ProgressDialog loading;
 
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewImage.this, "Uploading...", null,true,true);
            }
 
            @Override
            protected void onPostExecute(Bitmap b) {
                super.onPostExecute(b);
                loading.dismiss();
                imageView.setImageBitmap(b);
            }
 
            @Override
            protected Bitmap doInBackground(String... params) {
                String id = params[0];
                String add = "http://simplifiedcoding.16mb.com/ImageUpload/getImage.php?id="+id;
                URL url = null;
                Bitmap image = null;
                try {
                    url = new URL(add);
                    image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return image;
            }
        }
 
        GetImage gi = new GetImage();
        gi.execute(id);
    }
 
    @Override
    public void onClick(View v) {
        getImage();
    }
}

  • Now thats it for Android Download Image tutorial.
  • You can also download the source code of Android Download Image App from the link given below.

[easy_media_download url=”https://dl.dropboxusercontent.com/s/7eg2d1zq5brev1y/android-upload-image-to-server.zip?dl=0″ text=”Download Source”]

Video Demo of Android Download Image from MySQL Database

So thats it for this tutorial friends. If you are having any confusion for this Android Download Image Tutorial feel free to leave your comments. Thank You 🙂

Sharing is Caring:

  • Tweet
  • Share on Tumblr
  • More
  • Pocket
  • Print
  • Email

Related

Filed Under: Android Advance, Android Application Development Tagged With: android app development tutorials, android application development tutorial, android apps development tutorial for beginners, android download image

About Belal Khan

I am Belal Khan, I am currently pursuing my MCA. In this blog I write tutorials and articles related to coding, app development, android etc.

Comments

  1. Mohamad Arafat says

    September 7, 2015 at 2:30 am

    Hi Belal Khan,

    How to view all the images in my mysql database rather than search for the id?
    Can you help me?

    Reply
    • Belal Khan says

      September 7, 2015 at 3:02 am

      Stay tuned.. and I will post another tutorial showing how to fetch all the images from server at once 🙂

      Reply
      • Mohamad Arafat says

        September 10, 2015 at 2:35 am

        Thank you so much Belal :).

        Reply
        • Belal Khan says

          September 10, 2015 at 1:25 pm

          check this out
          http://www.simplifiedcoding.net/android-programming-tutorial-to-get-all-images-from-server/

          Reply
      • Sumanth says

        November 10, 2016 at 12:19 am

        Hello bilal,

        I am having database in wamp server
        When i upload from emulator it is working fine but when when i run it on my phone and give upload it is not working please help me to resolve this

        Reply
  2. cw fei says

    October 5, 2015 at 6:59 am

    Hi Belal Khan, I try my way to retrieve image file and store them into array along with other data type such as name, username, etc and parse them to JSON, my JSON now contains base64 string image, is this a good practice? MY JSON looks like this {“id”:”1,”name”:”cw fei”,”image”:/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABsSFBcUERsXFhceHBsgKEIrKCUlKFE6PTBCYFVlZF9VXVtqeJmBanGQc1tdhbWGkJ6jq62rZ4C8ybqmx5moq6T/2wBDARweHigjKE4rK06kbl1upKSkpKSkpKSkpKSkpKSkpKSkpKSkp…..”}

    I found it will be lag if obtain multiple images at once, so should I follow your way to obtain image one by one?

    Reply
    • Belal Khan says

      October 8, 2015 at 2:25 am

      Yeah your method will work slower..

      Reply
      • jerome says

        January 12, 2016 at 12:09 am

        belai can i get the php file

        Reply
  3. Monica says

    October 23, 2015 at 6:55 am

    Hi Belal ,this tutorial helps me a lot.
    How to upload multiple images to server ?

    Reply
    • Belal Khan says

      October 23, 2015 at 8:37 am

      I will try to post a tutorial for this 🙂

      Reply
  4. Rudi says

    October 23, 2015 at 8:27 am

    Hello,

    I have followed your tutorial here is my problem when i enter a id number in the search field then nothing happend,
    i have stored a picture in my database (LONGBLOB).

    can you please help me..

    i will gladly email you my code

    Reply
    • Belal Khan says

      October 23, 2015 at 8:38 am

      You are surely doing something wrong.. follow my code carefully.. it should work..

      Reply
      • Rudi says

        October 23, 2015 at 8:52 am

        Hello again,

        your a probably right, but i dont get any error.

        can i sendt your my code ?

        my databse is set op like this

        the table name is : images

        and i got 2 collums named id AI PRI and image LONGBLOB

        Reply
        • Belal Khan says

          October 23, 2015 at 8:55 am

          Connect with me on facebook.com/probelalkhan

          Reply
          • Rudi says

            October 23, 2015 at 9:02 am

            i dont have facebook sorry 🙁

            i do have linkdin

          • Rudi says

            October 23, 2015 at 9:06 am

            i also have Skype

  5. Rudi says

    October 23, 2015 at 8:58 am

    i dont have facebook sorry 🙁

    i do have linkdin

    Reply
    • Belal Khan says

      October 23, 2015 at 9:10 am

      Thats strange 😛 google.com/+BelalKhan
      Or come to gtalk [email protected]

      Reply
      • Rudi says

        October 23, 2015 at 9:26 am

        How do i save the project so i can sendt it to you ?

        Reply
        • Rudi says

          October 23, 2015 at 9:32 am

          i have sendt you a email

          Reply
          • Ruddi says

            October 23, 2015 at 10:51 am

            Your comment is awaiting moderation.

            Hello Again,

            i found out what the problem whas,

            when i uploaded from the app then the search field Works, but if i upload image directly from MYSQL then it does not Work.

            can you please tell me how i can create onclik on the image and then get a POPUP box there will show data from MYSQL database ?

      • Ruddi says

        October 23, 2015 at 1:08 pm

        Hey,

        is it possible that you can upload a tutorial where the user can clik on the image that is fetched from MYSQL and get a popup box

        Reply
  6. Ruddi says

    October 23, 2015 at 10:43 am

    Hello Again,

    i found out what the problem whas,

    when i uploaded from the app then the search field Works, but if i upload image directly from MYSQL then it does not Work.

    can you please tell me how i can create onclik on the image and then get a POPUP box there will show data from MYSQL database ?

    Reply
  7. Vinita says

    October 26, 2015 at 2:01 pm

    I have stored the name of image in database and uploaded the image on web server so how do I get the lnik of image to display in the application

    Reply
    • Belal Khan says

      October 26, 2015 at 2:05 pm

      http://simplifiedcoding.16mb.com/ImageUpload/getImage.php?id=1
      http://simplifiedcoding.16mb.com/ImageUpload/getImage.php?id=2

      These are the URLs for your images stored in db. Because the images are stored in blob format you cannot have a direct path to the file.

      Reply
      • Vinita says

        October 26, 2015 at 2:32 pm

        I have stored the link not the images that’s the problem..And I don’t have that much time to change everything.My images are stored on biz.nf web hosting server and my database is also stored on it.I want to know what link should I store in database to fetch images from the server.

        Reply
        • Belal Khan says

          October 26, 2015 at 2:58 pm

          You have to store the actual path to your images in your database.. You can see this tutorial
          http://www.simplifiedcoding.net/android-upload-image-using-php-mysql-android-studio/

          Reply
          • veerchandra sircar says

            March 15, 2016 at 11:11 am

            Hi Belal bro
            I am also following your code for uploading and downloading the image from server.I have done uploading successfully but i want download that image also but downloading is not happening. pls if possible help me.

  8. dara says

    November 6, 2015 at 1:55 pm

    I copied all your code for image uploading to server and also same table with same names but it does not work.O am using xamp as server.server. Plz suggest me what to do i have an important project for which image uploading is a part.it is due soon.

    Reply
  9. sikandar says

    December 3, 2015 at 5:36 am

    hi sir
    i have json data with image
    {“Response”:[{“name”:”raj”,”mobile”:”9931675657″,”image”:”image\/computer.jpg”},{“name”:”raj”,”mobile”:”8251843109″,”image”:”image\/ecbranch.jpg”},{“name”:”raj”,”mobile”:”9534979772″,”image”:”image\/bbb.png”}]}

    and i want to fetch data with image by giving name and show in listview . plse sir help me how can i do this or post the code for this

    Reply
    • Belal Khan says

      December 3, 2015 at 7:20 am

      Check this tutorial
      https://www.simplifiedcoding.net/android-custom-listview-with-images-using-recyclerview-and-volley/
      this will fulfil your requirements (y)

      Reply
  10. Subham Tripathi says

    December 20, 2015 at 1:21 pm

    Bhai i can’t understand the error like ( RequestHandler can not be resolved ) please help me..

    Reply
    • Belal Khan says

      December 20, 2015 at 2:12 pm

      You have to check the previous tutorial about uploading images
      https://www.simplifiedcoding.net/android-upload-image-to-server-using-php-mysql/

      Reply
  11. SUMIT KUMAR says

    January 4, 2016 at 6:55 pm

    how to store some images on mysql database manually and then fetching it and displaying it in a grid view in android studio? please give me some tutorials or code.

    Reply
    • SUMIT KUMAR says

      January 5, 2016 at 6:48 pm

      Please reply

      Reply
  12. Pfil says

    January 10, 2016 at 6:14 pm

    how do u upload and display image in app with one button

    Reply
  13. Harsh Dalwadi says

    January 12, 2016 at 5:56 am

    Hey..
    I have problem .
    I can’t retrieve image from server .
    I debug my code in that I can’t receive any image . In that i receive null .
    please help me out .

    Reply
    • JiYun says

      February 23, 2016 at 12:45 pm

      hey.. I experienced same problem…
      It did solved??

      Reply
      • AndiHong says

        March 14, 2016 at 2:49 am

        yes, i got null too,

        is there any problem about the code ? thanks if you can help me.. 😀

        Reply
  14. Aspiring Programmer says

    January 16, 2016 at 11:27 am

    Hi sir, i want to see only the codes for fetching images just like what I have watched in your demonstration in youtube. https://www.youtube.com/watch?v=kAQ2iORxl-k
    I would take this as a grateful gratitude if you grant my request. This will help me a lot. Thanks. 🙂

    Reply
  15. sameer hussain says

    January 20, 2016 at 2:18 pm

    hey how to fetch a numbers of image at once.. how to passs the array of image object from php.. please help me

    Reply
  16. Rashmi says

    February 1, 2016 at 10:34 am

    how to fetch image with text in gridview? from server with php.

    Reply
  17. christian saberon says

    February 20, 2016 at 1:34 pm

    hey ilove you tutorial, can you create an application in android that display image in mysql and populate list view with it

    Reply
  18. Nick says

    February 21, 2016 at 12:55 pm

    Hi,

    I am getting FileNotFound exception.

    java.io.FileNotFoundException: http://192.168.0.13:8888/android/include/GetImage.php?id=a.b.c
    02-21 13:35:24.549 13763-13888/app W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:210)

    Reply
  19. dipali says

    March 10, 2016 at 8:12 am

    Image is successfully uploaded and also stored in database but not displayed in upload folder, what can i do?

    Reply
    • AndiHong says

      March 14, 2016 at 3:02 am

      return null right ? same problem with me. 😀

      Reply
  20. ekhlas moahmed says

    March 18, 2016 at 9:38 am

    php mysql error
    MySQL said: Documentation

    #2006 – MySQL server has gone away

    Reply
  21. Mariëlle says

    March 26, 2016 at 9:22 am

    Is it possible to click on an item XYZ of the listViewItem not to see the item XYZ in more detail, but to connect to another mysql-table so to show in a new listview all the rows referring to the item XYZ?

    I’ve succesfully applied your instructions to create the first customlistview (Demand), and the second listview (Supplies). Both display correctly starting from the MainActivity, but I cannot start the second clicking on an item of the first.

    Thank you for your reply

    Reply
  22. Shilpa says

    April 12, 2016 at 12:27 pm

    Uploading is working fine,but when i enter id to view image I am not getting image.I have followed your tutorial , my problem when i enter id in the search field then n I am not getting image,

    Reply
    • shashi says

      June 28, 2016 at 6:58 am

      did u got solution?? me too facing same prblem

      Reply
      • Aditya Shirke says

        March 11, 2017 at 7:00 pm

        Same Problem

        Reply
  23. manikandan says

    May 24, 2016 at 5:59 am

    how can show multiple images where store in mysql database to grid view in android

    Reply
  24. Nikki says

    May 26, 2016 at 6:51 am

    hey !! First I tried to upload image using your code and it worked great but now when I am trying to fetch the image using your code its not working . It is not showing any error but i am not getting the image on imageview, plzz help me ..
    thanks in advance

    Reply
  25. Ratheesh says

    June 5, 2016 at 2:00 pm

    i got this error in my project

    — SkImageDecoder::Factory returned null

    Reply
  26. bob says

    June 8, 2016 at 9:01 am

    the uploading part works fine but im not able to view images back from the server. i tried debugging . the doinbackground method returns null in the image.

    Reply
  27. Mario says

    June 10, 2016 at 6:49 pm

    Hi Belal Khan, Thank you very much for sharing your knowledge, I have a question I want the button is in an activity and that giving click send him to another activity in which the image is displayed. your collaboration? Thanks.

    Reply
  28. kalyani says

    June 22, 2016 at 6:56 am

    Hello sir.. I have a doubt regarding displaying image in android app based on range of data stored in a table. I mean we have to display different image for different range of data in table. Iam using Android Version 5.0 and Wamp server for database connectivity. Please clarify my doubt. Thanks in advance.

    Reply
  29. shashi says

    June 28, 2016 at 6:56 am

    belal as people saying me too unable to view image in imageview solve the problem please…. thank u

    Reply
  30. shashi says

    June 28, 2016 at 7:47 am

    i got image from server successfully… you guyz need to hit the image url with id…. if anyone need the solution mail me your email id i will send you directly…..

    [email protected]

    Reply
    • Praveen says

      December 7, 2016 at 7:50 am

      Hi shashi, I am facing the same problem. Can you guide me in clearing this problem. my mail id is [email protected]

      Reply
  31. srini says

    July 21, 2016 at 7:21 am

    How to upload the at time upload the multiple image in php server please help me..

    Reply
  32. Jose says

    July 26, 2016 at 8:17 am

    i got this ….thnks ..
    is it possible to show this image to a button and image button also

    Reply
  33. Jose says

    July 26, 2016 at 8:23 am

    i got this …thanks…
    is it possible to view this image to a button or imagebutton

    Reply
  34. Vaibhav says

    September 21, 2016 at 12:44 pm

    Hello,
    I m Vaibhav. I have successfully uploaded some* images and fetched also. But when i try to upload an image with size of only 65KB or even higher ex. 252KB it is uploading it successfully but it is not fetching those images. Moreover when i choose these images from gallery i even don’t get preview for it. I have also experimented changing the blob with other types such as longblob, mediumblob but it is not helping. Sometimes the app is crashing when trying to upload an image with size of 400KB. Please help on this.

    Reply
  35. widi says

    September 24, 2016 at 7:37 am

    i got some error in this project
    /skia: — SkImageDecoder::Factory returned null

    how i can solve this problem?

    Reply
  36. ws says

    October 4, 2016 at 1:46 am

    Hi, may i know is that “http….?id+”+id this url is only works for the image that you uploaded to server, but what if you input that image directly to mysql database, what is the way to retrieve it? Any help will be appreciated.

    Reply
  37. Marco says

    October 13, 2016 at 10:42 am

    Hi, good tutorial….but i need to store in db and download drom db songs…can you help me,please?

    Reply
  38. Mk says

    January 6, 2017 at 5:45 pm

    facing this Error man .. please help me.

    Error : – SkImageDecoder::Factory returned null

    Reply
  39. shraddha says

    January 21, 2017 at 11:31 am

    hello ,
    how to retrieve images along with text and show them in listview

    Reply
    • shashikant says

      January 21, 2017 at 12:06 pm

      get it from json and set to the listview

      Reply
  40. siva says

    February 10, 2017 at 7:20 am

    hiii Belal Khan, i use this code but the image does not shown it shows the ERROR SkImageDecoder::Factory returned null I don’t no why
    .

    Reply
    • kalaivani says

      March 1, 2017 at 10:32 am

      hi everyone!!! i have the same problem plz help me

      Reply
  41. Denis says

    March 6, 2017 at 9:13 am

    I think u dont need to set the header in the php since we are echoing the image as a base64 string.This was causing me problems in my retrieval of the image

    Reply
    • Denis says

      March 7, 2017 at 7:16 am

      My bad mistook the decode function for encode

      Reply
  42. Udit Singh says

    April 2, 2017 at 2:04 pm

    Solution: for those where none error comes,in my case i change my image type in table of database from BLOB to Large Blob.If it helps please reply

    Reply
  43. Painter says

    April 18, 2017 at 6:29 am

    for those image return null:

    //call a function to get “echo [‘image’] (base64 raw data)”
    BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream, “utf-8”), 8);
    StringBuilder builder = new StringBuilder();
    String line = null;
    while ((line = bufReader.readLine()) != null) {
    builder.append(line + “\n”);
    }
    inputStream.close();
    result = builder.toString();
    return result;

    //after return result

    byte[] decodestring = Base64.decode(returned result, Base64.DEFAULT);
    image = BitmapFactory.decodeByteArray(decodestring, 0, decodestring.length);

    at least I solved it.

    Reply
  44. mark says

    April 29, 2017 at 3:15 pm

    hi, i have a problem of view image, I cant view the image, it return null, how to solve it?

    Reply
  45. droid says

    May 4, 2017 at 6:42 pm

    You have made great series but in my case image should be fetched when the app starts and can also be display offline without downloading, it is user based app. Image should be displayed in grid view and also be swipe using some page curl view /flip view.

    Please recommend me some from how to implement it.

    Thank you

    Reply
  46. Stanley Liem says

    May 13, 2017 at 12:07 pm

    image = null ?

    delete this header code from php file.

    ====header(‘content-type: image/jpeg’);=====

    i dont understand why your tutorial always have bug and we cant download the project in your link (badlink).
    if everything running well i think this is can be the best and simple tutorial for begginer.

    Reply
  47. anand kumbe says

    May 16, 2017 at 7:15 am

    in database change image datatype blob to long bob…. after that insert new image by app… after this retrieve a image easily… it does not show null..

    Reply
  48. Aman says

    May 31, 2017 at 12:21 pm

    The uploading part executed successfully. But while performing the fetching part i got thus error

    “D/skia: — decoder->decode returned false”

    Please help me with it

    Reply
  49. Chandrabhan Aher says

    June 13, 2017 at 12:30 pm

    do not get image because , do not call in Request Handler in sendGetRequest function into ViewImage class

    Reply
  50. rakshit says

    June 16, 2017 at 6:03 pm

    uploading is working great but while fetching i can’t see any image and there are no errors.

    Reply
  51. Korede says

    July 11, 2017 at 7:27 am

    i also have the same problem here, when upload the image into database it work fine but when trying to download the image it give no error and the image is not display.your tutorial is perfect if you can help to correct this error.
    thanks

    Reply
  52. rahul kumar says

    July 11, 2017 at 12:01 pm

    how to download source code

    Reply
  53. Aditya says

    September 5, 2017 at 8:22 am

    Sir in this video my error is coming of request handler because you have not created that class so please help me

    Reply
  54. Aman Adarsh says

    August 15, 2018 at 6:09 am

    How to use these images fetched from server in my image slider ?

    Reply

Leave a Reply to Monica Cancel reply

Your email address will not be published. Required fields are marked *

Search




Download our Android App

Simplified Coding in Google Play

About Me

Belal Khan

Hello I am Belal Khan, founder and owner of Simplified Coding. I am currently pursuing MCA from St. Xavier's College, Ranchi. I love to share my knowledge over Internet.

Connect With Me

Follow @codesimplified
Simplified Coding

Popular Tutorials

  • Android JSON Parsing – Retrieve From MySQL Database
  • Android Login and Registration Tutorial with PHP MySQL
  • Android Volley Tutorial – Fetching JSON Data from URL
  • Android Upload Image to Server using Volley Tutorial
  • Android TabLayout Example using ViewPager and Fragments
  • Retrieve Data From MySQL Database in Android using Volley
  • Firebase Cloud Messaging Tutorial for Android
  • Android Volley Tutorial – User Registration and Login
  • Android Upload Image to Server Using PHP MySQL
  • Android Navigation Drawer Example using Fragments




About Simplified Coding

Simplified Coding is a blog for all the students learning programming. We are providing various tutorials related to programming and application development. You can get various nice and simplified tutorials related to programming, app development, graphics designing and animation. We are trying to make these things simplified and entertaining. We are writing text tutorial and creating video and visual tutorials as well. You can check about the admin of the blog here and check out our sitemap

Quick Links

  • Advertise Here
  • Privacy Policy
  • Disclaimer
  • About
  • Contact Us
  • Write for Us

Categories

Android Advance Android Application Development Android Beginners Android Intermediate Ionic Framework Tutorial JavaScript Kotlin Android Others PHP Advance PHP Tutorial React Native

Copyright © 2017 · Simplified Coding· All rights Reserved. And Our Sitemap.All Logos & Trademark Belongs To Their Respective Owners·

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.