Expo Media Library permissions error on Android [React Native] - android

Hi I'm working on a react native app and I'm using expo-media-library to get user's photos but, only on android, when I try to ask for permissions using the following command I get the status as never_ask_again even if it's the first time I'm asking for permissions and I don't event refuse them because the popup didn't show up.
MediaLibrary.requestPermissionsAsync()
Then I tried to manually give permissions to the app, through settings, but when expo try to access to media library, here's the error that occurs.
Error: Missing MEDIA_LIBRARY permissions.
I also tried to use react-native-permissions to ask for permissions, but the result is the same.
Maybe someone has had this problem before and can help me, thanks.

=> Do you add this in your manifest file or not..?
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
const permission = await Permissions.getAsync(Permissions.CAMERA_ROLL);
if (permission.status !== 'granted') {
const newPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (newPermission.status === 'granted') {
//its granted.
}
} else {
....your code
}

Related

How do i add permissions to AndroidManifest via expo plugins?

My expo react native application comunicates with a zebra printer via a HTTP post request this works just fine in web , however on android and I suspect also iOS this isnt the case, from what i gather i need to add something along the lines of :
<uses-permission android:name="android.permission.INTERNET" />
Into androidmanifest.xml however expo doesnt give you direct access to that file , so i need to make a expo plugin that puts the permission into androidmanifest via expo.
I found this post teaching how to remove permissions however my current case requires me to add permissions ill still link the code from the post down here:
const { withAndroidManifest } = require("#expo/config-plugins")
module.exports = function androiManifestPlugin(config) {
return withAndroidManifest(config, async config => {
let androidManifest = config.modResults.manifest
// add the tools to apply permission remove
androidManifest.$ = {
...androidManifest.$,
"xmlns:tools": "http://schemas.android.com/tools",
}
// add remove property to the audio record permission
androidManifest["uses-permission"] = androidManifest["uses-permission"].map(
perm => {
if (perm.$["android:name"] === "android.permission.RECORD_AUDIO") {
perm.$["tools:node"] = "remove"
}
return perm
}
)
return config
})
}
Does anyone know how to add http permissions to my expo app? Thanks.
To add permissions you do not need expo-plugins.
You simply need to add the permission in your app.json (or app.config.js if you have dynamic configuration)
On Android, permissions are little bit simpler than iOS. In the managed workflow, permissions are controlled via the android.permissions property in your app.json file.
https://docs.expo.dev/guides/permissions/

How to detect permission dialog is denied by user

I am implementing take pictures from galley in my app, for which I am adding storage permission.
And I am requesting the permission from user using permission_handler package. And it is working perfectly in Android because it manages user state like permanently denied etc.
But the main issue in the iOS in which either user deny or allow always shows user granted permission(Means always providing the status == granted)
Please help if someone have same issue or I am doing anything wrong.
Thank you.
Add permission_handler: ^6.1.1 to you pubspec file
import it
import 'package:permission_handler/permission_handler.dart';
in you landing page or main.dart try calling this bellow functoin
bool storagePer = false;
void storageCheck() async {
var status = await Permission.storage.status;
if (!status.isGranted) {
await Permission.storage.request();
storagePer = true;
print('per: $storagePer');
}
}
To check if you have permission or not, use status.isGranted if it return true => permissionGranted else denied
to request permition use this await Permission.storage.request();

ReactNative : permission always return 'never ask again'

am using following code base to request the permission but it always return 'never ask again'
async requestPermission(request){
try{
const response= await PermissionsAndroid.request('PermissionsAndroid.PERMISSIONS.CAMERA',{
'title': 'Cool Photo App Camera Permission',
'message': 'Cool Photo App needs access to your camera ' +
'so you can take awesome pictures.'
})
console.log(response)
}catch(err){
}
this.getcurrentLocation()
}
//Response never_ask_again
I recently faced this issue about LOCATION service permission.
I forgot to add android.permission.ACCESS_FINE_LOCATION in AndroidManifest.xml.
So, I think you also forgot to add
<uses-permission android:name="android.permission.CAMERA" />
in your AndroidManifest.xml
I did clean and rebuild several times and finally started working, somehow the build cache is not properly updating.
Removing tools:node="remove" from AndroidManifest.xml fixed mine.
Replace
<uses-permission tools:node="remove" android:name="android.permission.CAMERA"/>
with
<uses-permission android:name="android.permission.CAMERA"/>
https://github.com/zoontek/react-native-permissions/issues/504#issuecomment-914417383

User Permissions in React Native for IOS/Android

I want to use Internet in app and need to ask for permission for both IOS/Android. I have checked out react-native-permissions but could not set up the module because of the react native link command. What is the easiest way to grant permissions in React-native? Any examples?
You can use internet by default if you use Expo (no need to ask internet permission). But if you want to ask the others permission check this link https://docs.expo.io/versions/latest/sdk/permissions.html
Example code :
async function getLocationAsync() {
const { Location, Permissions } = Expo;
const { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status === 'granted') {
return Location.getCurrentPositionAsync({enableHighAccuracy: true});
} else {
throw new Error('Location permission not granted');
}
}

HTML5 getCurrentPosition on PhoneGap going to error handler with weird null error, on Android only

I have a PhoneGap application which immediately sets window.location to be my on-internet site and carries on working from there. The app works great except for the following very strange behaviour.
I'm trying to get a geolocation by calling:
function geoErrorHandler(error) {
console.log("getCurrentPosition failed with error message: " + error.message);
}
function showPosition(position) {
// blah
}
var options = {maximumAge:60000, timeout:5000, enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(showPosition, geoErrorHander, options);
On iOS it works fine in my PhoneGap app. It also works fine when the page is just loaded in a desktop browser. On my Android PhoneGap app, however, it calls my geoErrorHandler. Which is fine - surely I can find out then what the problem was! Except it calls it with an error which has error.message = "" and error.code = null. Hrhum.
It's doing this on two separate devices and a fair amount of internet searching doesn't seem to reveal anyone else with this behaviour. What am I doing wrong?!
Maybe a permission problem?
Try adding to your manifest ACCESS_COARSE_LOCATION, ACCESS_LOCATION_EXTRA_COMMANDS and ACCESS_FINE_LOCATION permissions
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
http://developer.android.com/reference/android/Manifest.permission.html

Categories

Resources