How to detect permission dialog is denied by user - android

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();

Related

Expo Media Library permissions error on Android [React Native]

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
}

How to achieve ionic permissions on first load

My app currently asks for permissions when users open activities, I would like to have those permissions on app first load.
Example
One of my components (activity) needs callNumber permission and asking for this permission won't be popup until user opens that component, I would like to have that permission popup when user install the app for first time instead of when user goes to that specific activity.
Code
MyComponent.ts (my custom component activity that calling happen in that page)
import { CallNumber } from '#ionic-native/call-number/ngx';
constructor(
private callNumber: CallNumber,
) {...}
callEmergencies(event: any) {
this.callNumber.callNumber(event, true)
.then(res => {
Toast.show({
text: 'Calling ' + res + ' ...'
});
})
.catch(err => {
Toast.show({
text: 'something went wrong.'
});
});
}
App.module.ts (main module)
import { CallNumber } from '#ionic-native/call-number/ngx';
providers: [
CallNumber,
],
app.component.ts (Main component)
Has nothing about CallNumber plugin.
Question
How can I achieve that logic (asking permissions on first launch instead of in each activity)?
This is not possible or preferable. The new permissions paradigm is to request permissions when needed ('in context'). This way, the user should be in no doubt as to why you are requesting permission.
From the Android documentation:
Ask for permissions in context, when the user starts to interact with the feature that requires it.
iOS shares this idea:
Request personal data only when your app clearly needs it.

Getting list of available Wifi's on react native(android)

I want to get the available WiFi networks on my react-native android app. I went through a few blog posts and StackOverflow questions, but I am unable to achieve the desired functionality.
react-native-android-wifi is an npm package, which is expected to achieve the functionality, but I am getting an error of PermissionsAndroid not defined when trying to execute the code for asking user's permission to enable WiFi. Below is the code,
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Wifi networks',
'message': 'We need your permission in order to find wifi networks'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Thank you for your permission! :)");
} else {
console.log("You will not able to retrieve wifi available networks list");
}
} catch (err) {
console.warn(err)
}
Can someone please help me out here and please tell me how can I reach my desired outcome.
I used this in one of my projects https://github.com/blackdeve/react-native-wifi
Actually the library doesn't have a documented method for listing out available wifis but looking at the source code you can see there is a public method called loadWifiList
You need to follow the instructions on the github page and add stuff to settings.gradle. Here is the method I am talking about:
#ReactMethod
public void loadWifiList(Callback successCallback, Callback errorCallback) {
}

React-Native: How to access react-native app's permissions in Android?

I'm trying to access my react-native app's specific permissions in Android. I can access and pull up my app's info page in Android, but I can't go directly into the permissions screen from my app.
I am using react-native-android-open-settings to to achieve this. By using this I am able to access the app's info page, but can't access the specific permissions page for the app without the user having to click on permissions in App Info. The library can be found here: https://www.npmjs.com/package/react-native-android-open-settings
import AndroidOpenSettings from 'react-native-android-open-settings'
async goToSettings() {
if(Platform.OS === 'android') {
AndroidOpenSettings.appDetailsSettings()
} else {
Linking.canOpenURL('app-settings:').then(supported => {
if (!supported) {
console.log('Can\'t handle settings url');
} else {
return Linking.openURL('app-settings:');
}
}).catch(err => console.error('An error occurred', err));
}
}
The expected result is for it to open the permissions page and not the app info page.

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');
}
}

Categories

Resources