Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onResume()
- {
- super.onResume();
- if (!HasCameraPermission())
- {
- RequestCameraPermission();
- return;
- }
- }
- @Override
- public void onRequestPermissionsResult(int _RequestCode, String[] _Permissions, int[] _Results)
- {
- if (!HasCameraPermission())
- {
- Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG).show();
- if (!ShouldShowRequestPermissionRationale())
- {
- // Permission denied checking "Do not ask again".
- LaunchPermissionSettings();
- }
- finish();
- }
- }
- public boolean HasCameraPermission()
- {
- return this.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
- }
- public void RequestCameraPermission()
- {
- this.requestPermissions(new String[] {Manifest.permission.CAMERA}, 0);
- }
- public boolean ShouldShowRequestPermissionRationale()
- {
- return this.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA);
- }
- public void LaunchPermissionSettings()
- {
- Intent intent = new Intent();
- intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
- intent.setData(Uri.fromParts("package", this.getPackageName(), null));
- this.startActivity(intent);
- }
Add Comment
Please, Sign In to add comment