feat: add check for if device has a camera before sending out the image capture intent

This commit is contained in:
LucasGGamerM
2023-06-15 15:36:14 -03:00
parent a177d35c4f
commit 08866e0bea
2 changed files with 6 additions and 1 deletions

View File

@@ -1486,7 +1486,11 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST_CODE);
if(getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)){
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST_CODE);
} else {
Toast.makeText(getContext(), R.string.mo_camera_not_available, Toast.LENGTH_SHORT);
}
} else {
getActivity().requestPermissions(new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_CODE);
}