20
20
public class MainActivity extends AppCompatActivity {
21
21
private static final int CAMERA_PERMISSION_CODE = 0 ;
22
22
private static final String CAMERA_PERMISSION = Manifest .permission .CAMERA ;
23
+ private static final String CAMERA_PERMISSION_MESSAGE = "Camera permission is needed to use AR" ;
23
24
24
25
private PApplet sketch ;
25
26
@@ -45,10 +46,8 @@ protected void onResume() {
45
46
@ Override
46
47
public void onRequestPermissionsResult (int requestCode , String permissions [], int [] grantResults ) {
47
48
if (!hasCameraPermission ()) {
48
- Toast .makeText (this , "Camera permission is needed to use AR" , Toast .LENGTH_LONG )
49
- .show ();
49
+ Toast .makeText (this , CAMERA_PERMISSION_MESSAGE , Toast .LENGTH_LONG ).show ();
50
50
if (!shouldShowRequestPermissionRationale ()) {
51
- // Permission denied with checking "Do not ask again".
52
51
launchPermissionSettings ();
53
52
}
54
53
finish ();
@@ -89,17 +88,14 @@ private void requestCameraPermission() {
89
88
ActivityCompat .requestPermissions (this , new String []{Manifest .permission .CAMERA }, CAMERA_PERMISSION_CODE );
90
89
}
91
90
92
- /** Check to see if we need to show the rationale for this permission. */
93
91
private boolean shouldShowRequestPermissionRationale () {
94
92
return ActivityCompat .shouldShowRequestPermissionRationale (this , CAMERA_PERMISSION );
95
93
}
96
94
97
- /** Launch Application Setting to grant permission. */
98
95
private void launchPermissionSettings () {
99
96
Intent intent = new Intent ();
100
97
intent .setAction (Settings .ACTION_APPLICATION_DETAILS_SETTINGS );
101
98
intent .setData (Uri .fromParts ("package" , this .getPackageName (), null ));
102
99
this .startActivity (intent );
103
100
}
104
-
105
101
}
0 commit comments