UNPKG

4.16 kBTypeScriptView Raw
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10export interface Rationale {
11 title: string;
12 message: string;
13 buttonPositive: string;
14 buttonNegative?: string | undefined;
15 buttonNeutral?: string | undefined;
16}
17
18export type Permission =
19 | 'android.permission.READ_CALENDAR'
20 | 'android.permission.WRITE_CALENDAR'
21 | 'android.permission.CAMERA'
22 | 'android.permission.READ_CONTACTS'
23 | 'android.permission.WRITE_CONTACTS'
24 | 'android.permission.GET_ACCOUNTS'
25 | 'android.permission.ACCESS_BACKGROUND_LOCATION'
26 | 'android.permission.ACCESS_FINE_LOCATION'
27 | 'android.permission.ACCESS_COARSE_LOCATION'
28 | 'android.permission.RECORD_AUDIO'
29 | 'android.permission.READ_PHONE_STATE'
30 | 'android.permission.CALL_PHONE'
31 | 'android.permission.READ_CALL_LOG'
32 | 'android.permission.WRITE_CALL_LOG'
33 | 'com.android.voicemail.permission.ADD_VOICEMAIL'
34 | 'com.android.voicemail.permission.READ_VOICEMAIL'
35 | 'com.android.voicemail.permission.WRITE_VOICEMAIL'
36 | 'android.permission.USE_SIP'
37 | 'android.permission.PROCESS_OUTGOING_CALLS'
38 | 'android.permission.BODY_SENSORS'
39 | 'android.permission.BODY_SENSORS_BACKGROUND'
40 | 'android.permission.SEND_SMS'
41 | 'android.permission.RECEIVE_SMS'
42 | 'android.permission.READ_SMS'
43 | 'android.permission.RECEIVE_WAP_PUSH'
44 | 'android.permission.RECEIVE_MMS'
45 | 'android.permission.READ_EXTERNAL_STORAGE'
46 | 'android.permission.READ_MEDIA_IMAGES'
47 | 'android.permission.READ_MEDIA_VIDEO'
48 | 'android.permission.READ_MEDIA_AUDIO'
49 | 'android.permission.READ_MEDIA_VISUAL_USER_SELECTED'
50 | 'android.permission.WRITE_EXTERNAL_STORAGE'
51 | 'android.permission.BLUETOOTH_CONNECT'
52 | 'android.permission.BLUETOOTH_SCAN'
53 | 'android.permission.BLUETOOTH_ADVERTISE'
54 | 'android.permission.ACCESS_MEDIA_LOCATION'
55 | 'android.permission.ACCEPT_HANDOVER'
56 | 'android.permission.ACTIVITY_RECOGNITION'
57 | 'android.permission.ANSWER_PHONE_CALLS'
58 | 'android.permission.READ_PHONE_NUMBERS'
59 | 'android.permission.UWB_RANGING'
60 | 'android.permission.POST_NOTIFICATIONS'
61 | 'android.permission.NEARBY_WIFI_DEVICES';
62
63export type PermissionStatus = 'granted' | 'denied' | 'never_ask_again';
64
65export interface PermissionsAndroidStatic {
66 /**
67 * A list of permission results that are returned
68 */
69 RESULTS: {[key: string]: PermissionStatus};
70 /**
71 * A list of specified "dangerous" permissions that require prompting the user
72 */
73 PERMISSIONS: {[key: string]: Permission};
74 new (): PermissionsAndroidStatic;
75 /**
76 * @deprecated Use check instead
77 */
78 checkPermission(permission: Permission): Promise<boolean>;
79 /**
80 * Returns a promise resolving to a boolean value as to whether the specified
81 * permissions has been granted
82 */
83 check(permission: Permission): Promise<boolean>;
84 /**
85 * @deprecated Use request instead
86 */
87 requestPermission(
88 permission: Permission,
89 rationale?: Rationale,
90 ): Promise<boolean>;
91 /**
92 * Prompts the user to enable a permission and returns a promise resolving to a
93 * string value indicating whether the user allowed or denied the request
94 *
95 * If the optional rationale argument is included (which is an object with a
96 * title and message), this function checks with the OS whether it is necessary
97 * to show a dialog explaining why the permission is needed
98 * (https://developer.android.com/training/permissions/requesting.html#explain)
99 * and then shows the system permission dialog
100 */
101 request(
102 permission: Permission,
103 rationale?: Rationale,
104 ): Promise<PermissionStatus>;
105 /**
106 * Prompts the user to enable multiple permissions in the same dialog and
107 * returns an object with the permissions as keys and strings as values
108 * indicating whether the user allowed or denied the request
109 */
110 requestMultiple(
111 permissions: Array<Permission>,
112 ): Promise<{[key in Permission]: PermissionStatus}>;
113}
114
115export const PermissionsAndroid: PermissionsAndroidStatic;
116export type PermissionsAndroid = PermissionsAndroidStatic;