ReactNative : permission always return 'never ask again' - android

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

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
}

Why does the react-native-permissions cannot request the permission in Android?

Information
I tried to create an app to request permission in the react native side. There is a button in a screen to be clicked to check and request permission.
Problem
react-native-permission link: https://www.npmjs.com/package/react-native-permissions
When I follow the instruction in the link and create a demo app, I cannot request the permission and the request result is blocked.
Screenshots
Step 1: The main screen of app with permission request button
Step 2: The pop-out window
I click button at main screen(step 1), the step 2 will show and disappear quickly and back to screen at step 1.
I am new to React-Native, I don't know how to solve the problem. It is appreciated that anyone can help me to solve the problem. Thank you very much.
Github Link
https://github.com/TrifaC/HradwarePermissionTestApp.git
Try PermissionsAndroid from react-native package
import { PermissionsAndroid} from "react-native";
const requestCameraPermission = async () => {
try {
const granted = 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.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the camera");
} else {
console.log("Camera permission denied");
}
} catch (err) {
console.warn(err);
}
};
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Please Add in your AndroidManifest.xml

Remove background location access on Android

I am using react-native-geolocation-service to fetch the location of the user. On iOS it is easy to just ask for location access when the app is in the foreground, you just skip adding background location access as a capability. However, I don't understand how you remove this permission on Android. I don't have the ACCESS_BACKGROUND_LOCATION permission set and I'm still getting the option "Allow all the time" on e.g. my Pixel 2.
This is the code I am using to fetch the location of the user:
const getCurrentPosition = async (onSuccess, onError) => {
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'My title',
message: 'My message',
buttonPositive: 'Continue',
}
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
onError();
return;
}
}
Geolocation.getCurrentPosition(
(result) => {
const position = {
longitude: result.coords.longitude,
latitude: result.coords.latitude,
};
onSuccess(position);
},
(error) => {
onError();
},
{ enableHighAccuracy: true, maximumAge: 10000, timeout: 15000 }
);
};
Look into your main AndroidManifest.xml file (and by main I mean under android/app/src/main(COULD_BE_SOMETHING_ELSE_USUALLY_MAIN_BUT_YMMV)/AndroidManifest.xml)
You need to find a bunch of <uses-permission />. Check if one of these bad boys got ACCESS_BACKGROUND_LOCATION:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
No luck? Fear not, my dear friend. Here's a remedy for your battle-fatigued-from-dealings-with-react-native mind. Add this line under the last <uses-permission> tag.
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
tools:node="remove" />
May peace prevail.
Technical nitty gritty:
Actually, a library, like react-native-geolocation-service or react-native-background-geolocation, can alter final AndroidManifest.xml, which will go to a bundle edited heavily.
Simply deleting a line won't cut it, because you don't have an access to that final draft, cause it's auto-generated. You need to be one step ahead and use tools:node="remove" to make sure it will be deleted from the final version of the manifest file.
Sources:
[1] https://developer.android.com/studio/build/manifest-merge
[2] https://github.com/transistorsoft/react-native-background-geolocation/issues/1149

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

PhoneGap check Internet connection on device vs mobile browser

I am new to Phonegap and JqueryMobile. I need to check the internet connection on device. After seeing some solution on net I got confused about approaches. some solutions is suggesting to use PG API like network manager and connection while some using JQMobile method to check connection.
My question is which to prefer ? or what are the target areas for both the implementation ?
PhoneGap have own function to check Internet connection available or not.Here is that official document.
Check Internet is Online document.addEventListener("online", onOnline, false);
Check Internet is Offline document.addEventListener("offline", onOffline, false);
You need to set
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" /> permission in config.xml for android.
You have to add some permission in manifest as below,
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"> </uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"> </uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
Try this
Working example: http://jsfiddle.net/Gajotres/d5XYR/
In this case timer will check internet connection every 100 ms and set final result into a javascript global variable.
Everything depends on this line:
window.navigator.onLine -- it will be false if the user is offline.
Final solution:
var connectionStatus = false;
$(document).on('pagebeforeshow', '#index', function () {
setInterval(function () {
connectionStatus = navigator.onLine ? 'online' : 'offline';
}, 100);
$(document).on('click', '#check-connection', function () {
alert(connectionStatus);
});
});

Categories

Resources