Skip to content

Commit

Permalink
Merge pull request #211 from sendbird/fix/android-permissions
Browse files Browse the repository at this point in the history
[CLNP-5556] fix: remove non-required permissions from android
  • Loading branch information
bang9 authored Oct 29, 2024
2 parents d1ddb87 + 4646e34 commit 7f31104
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
9 changes: 5 additions & 4 deletions packages/uikit-react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ Add the following permissions to your `android/app/src/main/AndroidManifest.xml`
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.your.app">

<uses-permission android:name="android.permission.CAMERA" />
<!-- Permissions for voice message -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<!-- Permissions for image attachments -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />

<!-- Permissions for notifications (Android 13) -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

</manifest>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ function getAndroidStoragePermissionsByAPILevel(permissionModule: typeof Permiss
if (Platform.OS !== 'android') return [];

if (Platform.Version > 32) {
return [
permissionModule.PERMISSIONS.ANDROID.READ_MEDIA_AUDIO,
permissionModule.PERMISSIONS.ANDROID.READ_MEDIA_IMAGES,
permissionModule.PERMISSIONS.ANDROID.READ_MEDIA_VIDEO,
];
return [];
}

if (Platform.Version > 28) {
Expand Down Expand Up @@ -63,7 +59,7 @@ const createNativeFileService = ({
}): FileServiceInterface => {
const cameraPermissions: Permission[] = Platform.select({
ios: [permissionModule.PERMISSIONS.IOS.CAMERA, permissionModule.PERMISSIONS.IOS.MICROPHONE],
android: [permissionModule.PERMISSIONS.ANDROID.CAMERA],
android: [],
default: [],
});
const mediaLibraryPermissions: Permission[] = Platform.select({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ const createNativePlayerService = ({ audioRecorderModule, permissionModule }: Mo

public requestPermission = async (): Promise<boolean> => {
if (Platform.OS === 'android') {
const { READ_MEDIA_AUDIO, READ_EXTERNAL_STORAGE } = permissionModule.PERMISSIONS.ANDROID;
const permission = Platform.Version > 32 ? READ_MEDIA_AUDIO : READ_EXTERNAL_STORAGE;
if (Platform.Version > 32) return true;

const status = await permissionModule.check(permission);
const { READ_EXTERNAL_STORAGE } = permissionModule.PERMISSIONS.ANDROID;

const status = await permissionModule.check(READ_EXTERNAL_STORAGE);
if (status === 'granted') {
return true;
} else {
const status = await permissionModule.request(permission);
const status = await permissionModule.request(READ_EXTERNAL_STORAGE);
return status === 'granted';
}
} else {
Expand Down
14 changes: 6 additions & 8 deletions sample/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

<uses-permission android:name="android.permission.INTERNET" />

<!-- Permissions for FilePickerService -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Permissions for voice message -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<!-- Permissions for image attachments -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<!-- Permissions for VoiceMessage -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- Android 13 -->

<!-- Permissions for notifications (Android 13) -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<application
android:name=".MainApplication"
Expand Down

0 comments on commit 7f31104

Please sign in to comment.