SubscribeSubscribe with Androidlift to get new post on mail.

android camera image capturing and uploading to Php server

Android camera image capturing uploading

Android camera image capturing uploading,Camera app in android is quite easy to develop using android camera API. It is just a few lines of code. In the following example, we will simply invoke the existing android camera application in your android phone.
Let me explain the code part step by step.

Step 1:

  A quick way to enable taking pictures in your application without a lot of extra code is to use an Intent to invoke an existing Android camera application. A camera intent makes a request to capture a picture or video clip through an existing camera app and then returns control back to your application.
MediaStore – The Media provider contains meta data for all available media on both internal and external storage devices.
ACTION_IMAGE_CAPTURE – Standard intent action that can be sent to capture image through android camera application and return it back.
Step 2:
Now start the camera intent, through the method –  startActivityForResult(). On intent is started camera application UI appears on the screen and user can take picture.
cameraintent– Intent to start
CAPTURE_IMAGE_CAPTURE_CODE(101)  – A constant value (request code), If >= 0, this code will be returned in onActivityResult() when the activity exits.
When this activity exits, your onActivityResult() method will be called with the given requestCode.
Step 3:
The result from the activity will be returned to onActivityResult(int requestCode, int resultCode, Intent data), where we can perform our own functionality to process the result.
requestCode – The request code (CAPTURE_IMAGE_CAPTURE_CODE-101) that was supplied to startActivityForResult(), using which we can confirm which intent has sent back data.
resultCode – Result code sent back from the intent
data – An Intent, which can return result data to the caller
For camera and all network related tasks we have to provide permissions in our manifest file those are as follows –
Output :

Let’s start the coding.



Here our android application code is over.So let’s start for Php side.

For above code to work we need to create uploads folder in the same directory where you have put this file.
And run the project and you will see in logcat the following screenshot.
android camera image capturing uploading
android camera image capturing uploading
On  server side  you will get the uploaded image as below screenshot.
android camera image capturing uploading
android camera image capturing uploading
That’s it we are done.
Best Luck..!


  • Yogesh

    Nice Example …. I am Facing same problem in my project … now i am getting proper solution …. Thanks Androidlift …..

  • sunil

    how to save text along with the image..i mean how to send text and image to php file

  • sunil

    can i send any text in this line HttpFileUpload hfu = new HttpFileUpload(“http://domain name/web_service/file_upload.php”, “ftitle”, “fdescription”, fname); as ftitle..


      Yes u can send it over with extra parameter.

  • subedar

    tahnks for solution….but right now i facing with voice recording to sending on wammp server…So Please send me solution to my email_Id=
    Thanks for image sending on server….