Class Permissions
Checks and requests runtime permissions in one place.
This class declares nothing. A permission reaches the Android manifest
or the iOS Info.plist only because the build detected a feature class
that needs it (the camera, location, contacts and so on). Asking for a
permission no feature declared answers DENIED, and the log names the
reason.
#request(String, String) blocks until the user answers, so call it
from the EDT (it uses invokeAndBlock where needed) or from a
background thread.
if (Permissions.check(Permissions.CAMERA) != Permissions.GRANTED) {
int status = Permissions.request(Permissions.CAMERA, "To scan receipts");
Log.p("Camera permission: " + status);
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBluetooth devices.static final StringThe calendar.static final StringThe camera.static final StringThe address book.static final intThe permission is denied, or was never declared.static final intThe user denied it and the platform no longer shows the prompt; only the system settings can grant it now.static final intThe permission is granted.static final intGranted with restrictions, such as limited photo access or approximate location.static final StringLocation while the application is in use.static final StringLocation in the background.static final StringThe microphone.static final intThe user has not been asked yet.static final StringPosting notifications.static final StringThe photo library.static final intThe platform cannot tell, or has no such permission. -
Method Summary
Modifier and TypeMethodDescriptionstatic intThe current status of a permission.static booleanTrue when the permission is granted, fully or limited.static intAsks the user for a permission when it is not granted yet, and blocks until they answer.static voidsetImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
-
Field Details
-
CAMERA
-
MICROPHONE
-
LOCATION
-
LOCATION_ALWAYS
-
CONTACTS
-
CALENDAR
-
PHOTOS
-
NOTIFICATIONS
-
BLUETOOTH
-
UNKNOWN
public static final int UNKNOWNThe platform cannot tell, or has no such permission.- See Also:
-
NOT_DETERMINED
public static final int NOT_DETERMINEDThe user has not been asked yet.- See Also:
-
GRANTED
public static final int GRANTEDThe permission is granted.- See Also:
-
DENIED
public static final int DENIEDThe permission is denied, or was never declared.- See Also:
-
DENIED_PERMANENTLY
public static final int DENIED_PERMANENTLYThe user denied it and the platform no longer shows the prompt; only the system settings can grant it now.- See Also:
-
LIMITED
public static final int LIMITEDGranted with restrictions, such as limited photo access or approximate location.- See Also:
-
-
Method Details
-
setImplementation
public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
Parameters
impl: implementation instance
-
check
The current status of a permission. Never prompts.
Bluetooth is answered by
com.codename1.bluetooth.Bluetooth#hasPermission(BluetoothPermission), and the platform is asked only to tell a refusal from a question not asked yet. Contacts are not answered byDisplay#isContactsPermissionGranted()here: on iOS that call prompts.Parameters
permission: one of the permission names of this class
Returns
one of the status constants
-
request
Asks the user for a permission when it is not granted yet, and blocks until they answer.
Contacts go through
Display#isContactsPermissionGranted(), notifications throughDisplay#requestNotificationPermission(NotificationPermissionCallback)and Bluetooth throughcom.codename1.bluetooth.Bluetooth#requestPermissions(BluetoothPermission...)(scan and connect), so the prompt is the one those APIs show.Parameters
permission: one of the permission names of this classreason: the explanation shown where the platform asks for one
Returns
the status after the request
-
isGranted
True when the permission is granted, fully or limited.
Parameters
permission: one of the permission names of this class
Returns
true when granted
-