Search code examples
phpandroidserver-side

How to send and receive images programmatically from a server in Android


I intend to do an application that sometimes receives pictures from a server and sends pictures or other data back. As it should go over 3G or WIFI, I was thinking of PHP as the server side. It is easy to access online and can receive images.

I have some concerns:

  • Can an Android app receive image from a PHP site?
  • Can a PHP site use push messages to broadcast an image?
  • Can an Android app "upload" images to a PHP site?

If it is possible with PHP, is there any example for that?

If not:

What should I use as a server side to cover the aforementioned scenario?

Update:

Really? You want specific problem? Then here it is:

The following code can't download an image from a given php site:

DefaultHttpClient client=new DefaultHttpClient();
client.getImage(url);

I can't make it compile. What could be the problem?


Solution

  • Can an Android app receive image from a PHP site?

    Yes. Why not?:) You can send it for example as a binary data in your api response.

    Can a PHP site use push messages to broadcast an image?

    It can, but it should rather broadcast an image resource id or any other basic info to tell the android app that this resource is available and where it is. Then you will have to use another api call to get this particular resource. Push API limits amount of data you can send in push.

    Can an Android app "upload" images to a PHP site?

    Sure.

    Didn't try it but here is some example: http://androidexample.com/Upload_File_To_Server_-_Android_Example/index.php?view=article_discription&aid=83&aaid=106

    Here you can see how to get binary data in JSON but you can easily expose an image to be available under some URL like www.yourpage.com/image/image1234 and pass it to your android app. then you can use some library like AndroidQuery to lad it in your app.