I am stuck with this issue of Surfaceview and runtime perssion,
I have requirement of showing the camera preview using the Surfaceview at a main activity, So i am asking for the runtime permission when i call the code to show the camera preview.
But I am initializing the Surfaceview immediately after the permission is granted for camera, At that time the surfaceCreated() callback never calls and permission is also granted(I have checked from the Settings).
Once i kill the app and open again it works perfect after that.
Here is my initalising code,
in MainActivity,
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
initCameraPreview();
}
in initCameraPreview() method,
public void initCameraPreview(){
StartCameraPreview preview = new StartCameraPreview(context, surfaceView);
preview.onCreate();
}
I have created on class for SurfaceView, StartCameraPreview.java
public StartCameraPreview(Context context, SurfaceView surfaceView) {
this.mContext = context;
this.surfaceView = surfaceView;
}
public void onCreate() {
if (checkCameraHardware()) {
mCamera = getCameraInstance();
// configure preview
previewHolder = surfaceView.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
}
I cannot share much of the code, Sorry. So i have just added the initalization code. Did anyone face that issue or any one knows any solution for this?
Please help Thanks in adv.