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) {
}
Related
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();
My goal is to add a biometric option to my nativescript app.
The user gets a prompt in which i'm waiting for his authentication.
if authenticated - I want to console.log("Great"). and if not log "Problem".
I'm building it using Angular + Nativescript, so I registered Fingerprint as as provider, imported it and on constructor decalred:
constructor(private fingerprintAuth: FingerprintAuth);
And for the verifyFingerPrint, when page loads I call:
this.fingerprintAuth.available()
.then((result: BiometricIDAvailableResult) => {
console.log(`Biometric ID available? ${result.any}`);
if(result.any) {
if(result.face) {
console.log("HANDLE FACE WILL BE HERE SOON!");
}
if(result.touch) {
console.log("If not face, then touch id. Let's try it.");
this.fingerprintAuth.verifyFingerprint(
{
title: "Biometric Verification",
message: "Let's just make sure it's you..."
})
.then((data) => console.log("Authenticated, contacting server now...", data))
.catch((e) => console.log("Problem occured while authenticated.", e))
}
} else {
console.log("No Biometric Option is available, try adding one.");
}
});
}
The problem is, I am getting the fingerprint prompt as expected, but after a good or bad verification I never get the console.log part. .then / .catch - both won't log anything
And i'm not getting any errors..
I'm using sidekick,
local build on a Pixel 3 XL API 28 Emulator,
Plugin name:nativescript-fingerprint-auth
Nativescript + Angular Project
What could be the problem..?
Thanks!
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.
I'd like for users to be able to share a link (e.g. app.com/SKFLA - this is primarily because deep links on their own aren't clickable) via Facebook etc. When clicked, this redirects to a deep link app://SKFLA. If the app is installed, this opens the app - this is all working fine so far. But if the app isn't installed, I'd like to open the app store on the relevant page. Is this achievable? Thanks!
You need UNIVERSAL LINKS
Please check
IOS https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
Android
https://developer.android.com/training/app-links/
It might also require some extra server-side setup.
Not sure about native behavior.
We used third-party service like https://branch.io/deepviews/.
There is a bunch of similar services.
If someone is still stuck in this issue and needs easiest solution, you will love node-deeplink
1.) If app is installed: Calling an app through deep linking will always call componentDidMount of root component. So you can attach a listener there. Like:
Linking.getInitialURL()
.then(url => {
if (url) {
this.handleOpenURL({ url });
}
})
.catch(console.error);
Linking.addEventListener('url', this.handleOpenURL);
handleOpenURL(event) {
if (event) {
console.log('event = ', event);
const url = event.url;
const route = url.replace(/.*?:\/\//g, '');
console.log('route = ', route);
if(route.match(/\/([^\/]+)\/?$/)) {
const id = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
if (routeName === 'privatealbum') {
Actions.privateAlbum({ albumId: id });
}
}
}
}
2.) If app is not installed: Just set up a route in your server and node-deeplink package will handle the bridging between web browser to app store when a app is not installed in your mobile.
By this, both the cases will be handled without any struggle
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');
}
}