Android Device Camera Crash Issue In Android Version > 6.0
In some of the android devices which have android version > 6.0, when i access the camera, device camera gets opened and when i capture and accept the pic, camera is crashing(lo
Solution 1:
you need to ask run time permission because Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
ask for run time permission for camera using below code
Stringpermission= android.Manifest.permission.CAMERA;
if (ActivityCompat.checkSelfPermission(SearchCityClass.this, permission)
!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(SearchCityClass.this, newString[]
{permission}, 1);
}
now handle permisiion result
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// perform your action hereToast.makeText(this, "Camera_permission_granted ", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Camera_permission_not_granted ", Toast.LENGTH_SHORT).show();
}
}
}
Post a Comment for "Android Device Camera Crash Issue In Android Version > 6.0"