Skip to content

Commit

Permalink
Fix issue SecUSo#12
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrudd authored Sep 25, 2017
1 parent 634f832 commit 12e28c4
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ public class CameraMarshmallow implements ICamera {
public void init(Context context) {
mContext = context;
mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

try {
final String[] list = mCameraManager.getCameraIdList();
mCameraID = list[0];
for(final String cameraId : mCameraManager.getCameraIdList()){
CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
if(cOrientation == CameraCharacteristics.LENS_FACING_BACK){
mCameraID= cameraId;
}
}


} catch (CameraAccessException e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
}
Expand All @@ -36,8 +43,12 @@ public void init(Context context) {
@TargetApi(Build.VERSION_CODES.M)
public boolean toggle(boolean enable) {
try {
mCameraManager.setTorchMode(mCameraID, enable);
return true;
if (mCameraID != null){
mCameraManager.setTorchMode(mCameraID, enable);
return true;
}else{
return false;
}
} catch (CameraAccessException e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
return false;
Expand Down

0 comments on commit 12e28c4

Please sign in to comment.