Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

add requestPermissionsAndroid method to utils

ammarahm-edefc5f46a8f8e
diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.js
index b86c40e4d..37cf1b101 100755
--- a/apps/mobile/src/utils/utils.js
+++ b/apps/mobile/src/utils/utils.js
@@ -8,6 +8,7 @@ import {updateEvent} from '../components/DialogManager/recievers';
import {ACTIONS} from '../provider/actions';
import ESource from './event-source';
import EventSource from 'rn-eventsource';
+import {PERMISSIONS, requestMultiple, RESULTS} from 'react-native-permissions';
global.Buffer = require('buffer').Buffer;
@@ -53,6 +54,24 @@ export const history = {
selectedItemsList: [],
};
+export async function requestStoragePermission() {
+ let granted = false;
+ try {
+ const response = await requestMultiple([
+ PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE,
+ PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE,
+ ]);
+ granted =
+ response['android.permission.READ_EXTERNAL_STORAGE'] ===
+ RESULTS.GRANTED &&
+ response['android.permission.WRITE_EXTERNAL_STORAGE'] === RESULTS.GRANTED;
+ } catch (err) {
+ console.log(error);
+ } finally {
+ return granted;
+ }
+}
+
export function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);