Android - Simple Image Capture

Operating System

In this tutorial we will try to create a Simple Image Capture using Android. This simple application can be used to any system that needed the information about the location of the user. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc. So now let's do the coding.....

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things. Here's the link for the Android Studio

Layout Design

We will now create the design for the application, first locate the layout file called activity_main.xml, this is the default name when create a new activity. Then write these codes inside your layout file.
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android=""
  3. xmlns:app=""
  4. xmlns:tools=""
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context="com.razormist.simpleimagecapture.MainActivity">
  9. <ImageView
  10. android:id="@+id/iv_image"
  11. android:layout_width="match_parent"
  12. android:layout_height="match_parent"
  13. android:layout_above="@+id/btn_capture"
  14. app:srcCompat="@mipmap/ic_launcher" />
  16. android:id="@+id/btn_capture"
  17. android:layout_height="wrap_content"
  18. android:layout_width="wrap_content"
  19. android:text="Capture"
  20. android:layout_marginBottom="30dp"
  21. android:layout_alignParentBottom="true"
  22. android:layout_centerHorizontal="true" />
  23. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code. It describe the overall information about the application. It contains some libraries that needed to access the several method within the app.
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android=""
  3. package="com.razormist.simpleimagecapture">
  5. <uses-feature android:name="android.hardware.camera2" android:required="true"/>
  7. <application
  8. android:allowBackup="true"
  9. android:icon="@mipmap/ic_launcher"
  10. android:label="@string/app_name"
  11. android:roundIcon="@mipmap/ic_launcher_round"
  12. android:supportsRtl="true"
  13. android:theme="@style/AppTheme">
  14. <activity android:name=".MainActivity"
  15. android:configChanges="orientation"
  16. android:screenOrientation="portrait">
  17. <intent-filter>
  18. <action android:name="android.intent.action.MAIN" />
  20. <category android:name="android.intent.category.LAUNCHER" />
  21. </intent-filter>
  22. </activity>
  23. </application>
  24. </manifest>

The Main Function

This code contains the main function of the application. This code will force open the built camera to take a shot and display it in the ImageView at the same time. To start with first locate your MainActivity java file and open it, then write these variable inside the MainActivity class.
  1. Button btn_capture;
  2. ImageView iv_image;
  3. int code = 1;
Then write these method to make to code work correctly.
  1. public void onActivityResult(int code, int resultCode, Intent data) {
  2. if(code == this.code){
  3. if(resultCode == RESULT_OK){
  4. Bundle bundle = new Bundle();
  5. bundle = data.getExtras();
  6. Bitmap bmp;
  7. bmp = (Bitmap)bundle.get("data");
  8. iv_image.setImageBitmap(bmp);
  9. }
  10. }
  11. }
Finally, initialize the require methods inside the onCreate method to run the application.
  1. btn_capture = (Button)findViewById(;
  2. iv_image = (ImageView)findViewById(;
  6. btn_capture.setOnClickListener(new View.OnClickListener() {
  7. @Override
  8. public void onClick(View v) {
  9. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  10. if(intent.resolveActivity(getPackageManager()) != null){
  11. startActivityForResult(intent, code);
  12. }
  13. }
  14. });
Try to run the app and see if it worked. There you have it we have created a Simple Image Capture using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment