This video shows the steps to create a simple camera application for android smartphone using android studio.
In this video, a very simple approach has been shown to do the application development. It just shows how we can use our phone camera to get the preview image.
Since we will be getting the preview, we can also use this App like a Mirror App which shows the image seen by front camera. And the smartphone screen can be used like mirror screen to show or project the mirror image.
The video take you slowly through the development showing how to code each line of the program. Towards the end it also shows how to do the setting of the emulator to use your Android virtual device (AVD), that is emulator, to test this App. So, it is suggested to watch this tutorial till the end.
For any questions please comment in this video and it will be answered as soon as possible.
If you like this video please subscribe to the channel for further update on development of similar Apps.
We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com
Source Code:
package com.example.mycamera;
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
private CameraCaptureSession myCameraCaptureSession;
private String myCameraID;
private CameraManager myCameraManager;
private CameraDevice myCameraDevice;
private TextureView myTextrureView;
private CaptureRequest.Builder myCaptureRequestBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);myTextrureView = findViewById(R.id.textureView);
myCameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
openCamera();
}private CameraDevice.StateCallback myStateCallBack = new CameraDevice.StateCallback() {
@Override
public void onOpened(@NonNull CameraDevice camera) {
myCameraDevice = camera;
}@Override
public void onDisconnected(@NonNull CameraDevice camera) {
myCameraDevice.close();
}@Override
public void onError(@NonNull CameraDevice camera, int error) {
myCameraDevice.close();
myCameraDevice = null;}
};private void openCamera() {
try {
myCameraID = myCameraManager.getCameraIdList()[0];ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
}
myCameraManager.openCamera(myCameraID, myStateCallBack, null);}
catch (Exception e){
e.printStackTrace();
}
}public void cameraPreview(View view){
SurfaceTexture mySurfaceTexture = myTextrureView.getSurfaceTexture();
Surface mySurface = new Surface(mySurfaceTexture);try {
myCaptureRequestBuilder = myCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
myCaptureRequestBuilder.addTarget(mySurface);myCameraDevice.createCaptureSession(Arrays.asList(mySurface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
myCameraCaptureSession = session;
myCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
try {
myCameraCaptureSession.setRepeatingRequest(myCaptureRequestBuilder.build(), null, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {}
}, null
);
} catch (CameraAccessException e) {
e.printStackTrace();
}}
}
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.mycamera”><uses-permission android:name=”android.permission.CAMERA”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
<uses-permission android:name=”android.permission.RECORD_AUDIO”/>
<uses-feature android:name=”android.hardware.camera2″/><application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application></manifest>
<?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:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”.MainActivity”><TextureView
android:id=”@+id/textureView”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” /><Button
android:id=”@+id/button”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”150dp”
android:layout_marginTop=”250dp”
android:onClick=”cameraPreview”
android:text=”Capture” />
</RelativeLayout>
Sir Can you please send the whole code with Image to text including camera error please sir
I think what you are looking for is an OCR code. It is shared in the below link:
https://programmerworld.co/android/how-to-create-your-optical-character-recognition-ocr-android-app-and-convert-the-text-into-speech/
I hope it helps.
Cheers
Programmer World
–
Hello sir. I just want a slight change in the application. You have a good experience of Matlab and android app. I want your contact detail for further discussion over it. I also mailed you same thing please revert me back as per your availability.
Can you please let us know the details of the modifications needed in your App?
We will check it and try to help.
Cheers
Programmer World
–
I want an Android app that click image store it in phone. Then I want to process that image on matlab image processing toolbox at my laptop. And send back the results of processing to the application.
Use a database to transact the image and its modified version between Android and matlab.
One example of storing image in db is discussed in below page:
https://programmerworld.co/android/how-to-store-image-in-ms-sql-server-and-retrieve-it-from-your-android-app/
Cheers
Programmer World
–
Can’t you make it for me ? I know it’s a simple task for you . I can pay you for the work you put in .
Please connect with us on our email ID: programmerworld1990@gmail.com
Cheers
Programmer World
–