Tuesday, 24 June 2025

Earn from youtube

Contact Info

  • ADDRESS: 851, LG, Sector 3F, Sector 3, Vaishali, Ghaziabad, Uttar Pradesh 201010

  • PHONE: +91 7986794481

  • E-MAIL: contact@technicalspeaks.com

  • Home  
  • Source Code for Camera Implementation in Android Studio
- android

Source Code for Camera Implementation in Android Studio

In this blog, you will get the source code for implementing camera in your android app. You just need to copy this code and use it in your app. 1. activity_main.xml 2. MainActivity.java 3. AndroidManifest.xml Output: Connect with us:

In this blog, you will get the source code for implementing camera in your android app. You just need to copy this code and use it in your app.

1. activity_main.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout 
    xmlns:android=”http://schemas.android.com/apk/res/android”
   xmlns:app=”http://schemas.android.com/apk/res-auto”
   xmlns:tools=”http://schemas.android.com/tools”
   android:id=”@+id/container”
   android:layout_width=”match_parent”
   android:layout_height=”match_parent”
   tools:context=”.Camera_Demo”>
 
    <Button
        android:layout_marginTop=”10sp”
        android:layout_width=”fill_parent”
        android:layout_height=”wrap_content”
        android:text=”Camera Button”
        android:id=”@+id/btnCamera”
        android:textColor=”#FFFFFF”
        android:background=”#3F51B5″
        android:textStyle=”bold” />
 
    <ImageView
        android:layout_width=”match_parent”
        android:layout_height=”match_parent”
        android:id=”@+id/capturedImage”
        android:layout_below=”@+id/btnCamera”/>
 
</RelativeLayout>

2. MainActivity.java

import …

public class Camera_Demo extends AppCompatActivity {

    private Button btnCamera;
    private ImageView capturedImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera__demo);

        
        Typeface font = Typeface.createFromAsset( getAssets(), “fonts/TitilliumWeb-Bold.ttf” );
        btnCamera = (Button) findViewById(R.id.btnCamera);

        capturedImage= (ImageView) findViewById(R.id.capturedImage);

        btnCamera.setTypeface(font);

        btnCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openCamera();
            }
        });


    }

    private void openCamera() {
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == RESULT_OK) {
            Bitmap bp = (Bitmap) data.getExtras().get(“data”);
            capturedImage.setImageBitmap(bp);
        }
    }


}

3. AndroidManifest.xml

Add Camera Permission in your manifest file:
<uses-permission android:name=”android.permission.CAMERA” />

Output:

Source Code for Camera Implementation in Android Studio

Connect with us:

Leave a comment

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

About Us

Providing expert blogs on web, SEO, tech, YouTube, and more, helping readers stay updated and grow in the digital world.

Email Us: contact@technicalspeaks.com

Contact: +91 7986794481

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!