My Ionic app (in development) used to work fine with Android 5. When testing it with a new Google Nexus 6P (Android 6.0.1) I get the error message in the title. My camera code is simple (see below). What am I missing to make it work again?
With a little research, I discovered a plugin as been developed at:
You should use this to check if permissions have been requested, and if so then execute your request. If they do not allow, you can simply show an alert or something telling the user that it is required.
Hi EffkaT, thanks for the information.
Do you happen to know how to modify the manifest file (or elsehwre) to ask for permission to use camera in that form:
I haven’t tested it, but you shouldn’t need to add anything new to the manifest, instead just install the plugin, and call
//only if v6 or greater
if (ionic.Platform.version() >= 6) {
var permissions = window.plugins.permissions;
//do we already have permissions
permissions.hasPermission(function(status){
if(!status.hasPermission) {
//if not, warn in console
var errorCallback = function() {
console.warn('Camera permission is not turned on');
}
//make request for permissions
permissions.requestPermission(function(status) {
//do we still not have permissions? user denied. Do something here
if( !status.hasPermission ) userdenied();
}, function(){}, permissions.CAMERA);
}
}, function(){}, permissions.CAMERA);
}
What this would do is check the version of android, if it is above 6.0, it will request permission, otherwise it will ignore the check.
Thanks much. I guess userdenied() was meant to be errorCallback() .
But the problem persists. When running it I get the error message that permission is not turned on. But there is no dialog popping up requesting such permission.
The Ionic app was installed using “ionic run android” . It did not ask for permissions setting when installed. How do we make ionic app display and request permissions when they are installed?
BTW when looking at the Settings / apps / my-under-dev-app it allows setting all kind of permissions such as “contacts”, “accounts”, location, etc, but not the Camera. Should specific libraries be used with the camera (vs the navigator.camera.getPicture I have been using in order to get the Camera permissions available?
got it. For whomever may face this issue, the following line needs to be added to ./platforms/android/AndroidManifest.xml
and the line is: <uses-permission android:name="android.permission.CAMERA" />
And of course the code EffakT provided above needs to be added as well. Note that there is a typo there, instead of userdenied the correct call is to errorCallback .
@EffkT, i tried this it didnot work for me.
im using ionic 1.3.1 and angular 1.5.3.
the app just stops when i run it in the emulator and it crashes when i try to run it on a phone with android marshmallow (6.0)