cordova-plugin-android-permissions
cordova-plugin-android-permissions copied to clipboard
Not requesting for permissions popup for android 6 and above.
Hello, I am trying to integrate the code in ionic 1. I am not getting the popup of requesting permission on android 6 and above both emulator and android phones.
Please find my code below
app.js
$ionicPlatform.on('deviceready', function(){
var permissions = cordova.plugins.permissions;
permissions.hasPermission(permissions.WRITE_EXTERNAL_STORAGE, function(status) {
if (status.hasPermission) {
alert('you already have permission');
} else {
alert('need to request permission');
permissions.requestPermission(permissions.WRITE_EXTERNAL_STORAGE, successCallback, errorCallback);
function errorCallback() {
alert('permission not turned on');
}
function successCallback(status) {
if (status.hasPermission) {
alert('user accepted, here you can start your own plugin');
}
}
}
});
});
AndroidManifest.xml
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Ionic Info
Ionic:
ionic (Ionic CLI) : 4.1.0 (/home/user/lib/node_modules/ionic)
Ionic Framework : ionic1 1.3.3
@ionic/v1-toolkit : 1.0.6
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 6.4.0, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, (and 32 other plugins)
System:
Android SDK Tools : 26.1.1
NodeJS : v6.9.0 (/home/user/.nvm/versions/node/v6.9.0/bin/node)
npm : 6.6.0
OS : Linux 4.15
Hello, I'm facing the same issue.
Even I am facing the same issue. I have tried upgrading the cordova-android version to 7.1.0. But still the permission popup is not popping out.
@nivebiju I make this work by requesting permission imediatly after the first try to access some resource (in my case, gps). I don't know where i found this info, but works.
I'm facing the same issue. @lkonzen-garupa you are first trying to access to some resources and in error function you are requesting permission?
@nichovski I'm not waiting the error, just using the following:
navigator.geolocation.watchPosition(success, error, {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: Infinity
});
cordova.plugins.permissions.checkPermission(
[permissions.ACCESS_FINE_LOCATION],
function(status) {
if (status.hasPermission) {
successCB(status);
} else {
permissions.requestPermission(
[permissions.ACCESS_FINE_LOCATION],
function(status) {
if (!status.hasPermission) {
errorCB();
} else {
successCB(status);
}
},
errorCB
);
}
}
);
@lkonzen-garupa thanks, I will try that.
@lkonzen-garupa As soon as I open, the mobile app crashes in Android 8.0 and above. If I manually give permissions,then the app is working properly. Any solution?
@nivebiju are you shure about this error beiing coused by this plugin? Any logcat info?
@lkonzen-garupa I guess so. As soon as I give permissions why is it working then?
Here is the log
Caused by: java.lang.SecurityException:
at android.os.Parcel.readException (Parcel.java:2029)
at android.os.Parcel.readException (Parcel.java:1975)
at android.content.IContentService$Stub$Proxy.registerContentObserver (IContentService.java:788)
at android.content.ContentResolver.registerContentObserver (ContentResolver.java:1930)
at android.content.ContentResolver.registerContentObserver (ContentResolver.java:1919)
at org.xwalk.core.internal.extension.api.contacts.Contacts.
@nivebiju I think this may not be a permission plugin error. Can you try a new clean app with just the plugin to verify.
@lkonzen-garupa Set targetSdkVersion to 23 in config.xml. It will automatically asks permission for accessing contacts and so on.
@nivebiju I've tried with targetSdkVersion 23 for camera permission but it is not asking for permission. Still trying to find a way how to solve this issue? If someone solved it, we are welcome to hear how :)
@nichovski If Cordova -android version above 6.0 , then set minSdkVersion to 19 and targetSdkVersion to 23 in config.xml . After adding platforms , go and check whether AndroidManifest.Xml file has min and target versions set.. Can you please post the log for more clarification..??
Any news about this issue, I am having the exact problem, except when I run with live reloading it works perfectly. But when I generate an apk and installed it myself, nothing happens. Even when I give the permissions manually form setting, the app still unable to read from storage. My code (home component):
ngOnInit() {
this.androidPermissions.requestPermissions(
[
this.androidPermissions.PERMISSION.CAMERA,
this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE,
this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE,
]);
}
My environment setup:
Ionic:
Ionic CLI : 5.4.16 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 5.3.2
@angular-devkit/build-angular : 0.901.12
@angular-devkit/schematics : 9.1.12
@angular/cli : 9.1.12
@ionic/angular-toolkit : 2.3.3
@ionic-native/android-permissions 5.28.0
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 23 other plugins)
cordova-plugin-android-permissions 1.0.2
Utility:
cordova-res : not installed
native-run : 1.0.0
System:
Android SDK Tools : 26.1.1 (/home/sayto/Android/Sdk/)
NodeJS : v14.9.0 (/home/sayto/.nvm/versions/node/v14.9.0/bin/node)
npm : 6.14.8
OS : Linux 5.4
Having the same issue, this code snippet always returns "request fulfilled: false" without having shown any pop up
this.androidPermission.checkPermission(this.androidPermission.PERMISSION.ACCESS_FINE_LOCATION)
.then(
res => {
if (!res.hasPermission) {
this.androidPermission.requestPermission(this.androidPermission.PERMISSION.ACCESS_FINE_LOCATION)
.then(
res => {
this.toastService.showToast('request fulfilled: ' + res.hasPermission);
// always returns false
},
err => {
this.toastService.showToast('request rejected: ' + err);
}
)
}
},
err => {
this.toastService.showToast('check rejected: ' + err);
}
);
Actually just "solved" my permission issue on android by going into the AndroidManifest.xml file and manually adding the line <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />.
Now the pemission gets asked via the popup if not present.
any update on this? I need to request permission for BLUETOOTH_SCAN as I need to request for nearby devices permission
- Tried calling requestPermission() but I didn't received any popup
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.BLUETOOTH_SCAN).then(
result => {
console.log('Has permission?', result.hasPermission)
if (!result.hasPermission) {
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.BLUETOOTH_SCAN).then((res) => {
console.log('Has permission response after requesting?', res.hasPermission);
});
}
},
err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.BLUETOOTH_SCAN)
);
- Tried adding it in android manifest but didn't received popup
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
Do I need to add anything else to request permission?
My update for above issue. This worked after changing this.androidPermissions.PERMISSION.BLUETOOTH_SCAN to 'android.permission.BLUETOOTH_SCAN'
Thank yo @mdivya-symplr, save me!