Skip to content

Instantly share code, notes, and snippets.

@Deri-Kurniawan
Last active November 7, 2022 06:37
Show Gist options
  • Save Deri-Kurniawan/8deeb50a125b0c938bac265b230fcd2a to your computer and use it in GitHub Desktop.
Save Deri-Kurniawan/8deeb50a125b0c938bac265b230fcd2a to your computer and use it in GitHub Desktop.
All android permission at one file

Request Android Permissions

This Gist is for Tutorial Request All Permissions Android React Native

Outside of React Native App. You can also use the AndroidManifest.xml permission request. But only take all <uses-permission/>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp">
<!-- All Permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.ACCEPT_HANDOVER" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.UWB_RANGING" />
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
// React Native Uses Permission
import React from 'react';
import {Button, Linking, PermissionsAndroid, ScrollView} from 'react-native';
const PERMISSIONS_TYPE = [
'READ_CALENDAR',
'WRITE_CALENDAR',
'CAMERA',
'READ_CONTACTS',
'WRITE_CONTACTS',
'GET_ACCOUNTS',
'ACCESS_FINE_LOCATION',
'ACCESS_COARSE_LOCATION',
'ACCESS_BACKGROUND_LOCATION',
'RECORD_AUDIO',
'READ_PHONE_STATE',
'CALL_PHONE',
'READ_CALL_LOG',
'WRITE_CALL_LOG',
'ADD_VOICEMAIL',
'USE_SIP',
'PROCESS_OUTGOING_CALLS',
'BODY_SENSORS',
'SEND_SMS',
'RECEIVE_SMS',
'READ_SMS',
'RECEIVE_WAP_PUSH',
'RECEIVE_MMS',
'READ_EXTERNAL_STORAGE',
'WRITE_EXTERNAL_STORAGE',
'BLUETOOTH_CONNECT',
'BLUETOOTH_SCAN',
'BLUETOOTH_ADVERTISE',
'ACCESS_MEDIA_LOCATION',
'ACCEPT_HANDOVER',
'ACTIVITY_RECOGNITION',
'ANSWER_PHONE_CALLS',
'READ_PHONE_NUMBERS',
'UWB_RANGING',
];
async function requestPermission(PERMISSION_TYPE) {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS[PERMISSION_TYPE],
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log(`You can use ${PERMISSION_TYPE}`);
} else {
console.log(`${PERMISSION_TYPE} permission denied`);
}
} catch (err) {
console.warn(err);
}
}
export default function App() {
return (
<ScrollView>
{PERMISSIONS_TYPE.map((TYPE, index) => (
<Button
key={index}
color={index % 2 === 0 ? 'dodgerblue' : 'blue'} // to make odd event button color
title={`Allow ${TYPE}`}
onPress={() => requestPermission(TYPE)}
/>
))}
<Button
color="black"
title="Open Settings"
onPress={() => Linking.openSettings()} // opens settings your app
/>
</ScrollView>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment