Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Permissions
- Object
- 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);
}Fields
Methods
public static void setImplementation(CodenameOneImplementation impl) | Invoked internally from Display, this method is for internal use only |
public static int check(String permission) | The current status of a permission. |
public static int request(String permission, String reason) | Asks the user for a permission when it is not granted yet, and blocks until they answer. |
public static boolean isGranted(String permission) | True when the permission is granted, fully or limited. |
Inherited methods
Field details
CAMERA
public static final String CAMERA = "camera"MICROPHONE
public static final String MICROPHONE = "microphone"LOCATION
public static final String LOCATION = "location"LOCATION_ALWAYS
public static final String LOCATION_ALWAYS = "locationAlways"CONTACTS
public static final String CONTACTS = "contacts"CALENDAR
public static final String CALENDAR = "calendar"PHOTOS
public static final String PHOTOS = "photos"NOTIFICATIONS
public static final String NOTIFICATIONS = "notifications"BLUETOOTH
public static final String BLUETOOTH = "bluetooth"UNKNOWN
public static final int UNKNOWN = 0NOT_DETERMINED
public static final int NOT_DETERMINED = 1GRANTED
public static final int GRANTED = 2DENIED
public static final int DENIED = 3DENIED_PERMANENTLY
public static final int DENIED_PERMANENTLY = 4LIMITED
public static final int LIMITED = 5Method details
setImplementation
public static void setImplementation(CodenameOneImplementation impl)Parameters
implCodenameOneImplementation- implementation instance
check
public static int check(String permission)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 by
Display#isContactsPermissionGranted() here: on iOS that call prompts.
Parameters
permissionString- one of the permission names of this class
Returns
request
public static int request(String permission, String reason)Asks the user for a permission when it is not granted yet, and blocks until they answer.
Contacts go through Display#isContactsPermissionGranted(),
notifications through Display#requestNotificationPermission(NotificationPermissionCallback)
and Bluetooth through
com.codename1.bluetooth.Bluetooth#requestPermissions(BluetoothPermission...)
(scan and connect), so the prompt is the one those APIs show.
Parameters
permissionString- one of the permission names of this class
reasonString- the explanation shown where the platform asks for one
Returns
isGranted
public static boolean isGranted(String permission)Parameters
permissionString- one of the permission names of this class