Closed terhoraj closed 8 years ago
Can you share the code you are using to ask for and setup your permissions?
Yes, also note that I have tried one at the time and I'm getting same error. One at the time = only one request at all.
var permissionsModule = require("nativescript-permissions");
permissionsModule.requestPermission([
android.Manifest.permission.CAMERA,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE],
"Reason here!")
.then(function(result) {
console.log(result);
console.log("X permissions granted!");
})
.catch(function(result) {
console.log(result);
console.log("X permissions denied!");
});
Ok, I pasted your code into my demo app and reformatted it slightly and it works fine. The demo app has been updated on github.
I did actually find a corner case with permissions on Android < 5; where if you forgot to give all the perms in the manifest it would fail to resolve the promise properly. But technically you are supposed to include all the perms you need in the manifest so this should have been a corner case that wouldn't have effected apps in production.
Please make sure you are using NS-permissions 1.1.1 (or later) and verify you are still having issues. I ran this on both a Android 4.4 and 6.0 device.
Thank you for your help. Turns out that the problem was that this code did not run from view-model at the moment when view-model was created. I did transfer all code under navigatedTo event and it's working just fine. I have all permission listed on manifest. I don't know what is happening but this is my fault once again.
By the way, thank you Nathanael for all the plugins you have made!
I'm getting this error from ".catch(function(result)" result:
Error: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference android.support.v4.content.ContextCompat.checkSelfPermission(ContextCompat.java:387) com.tns.Runtime.callJSMethodNative(Native Method) com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:861) com.tns.Runtime.callJSMethodImpl(Runtime.java:726) com.tns.Runtime.callJSMethod(Runtime.java:712) com.tns.Runtime.callJSMethod(Runtime.java:693) com.tns.Runtime.callJSMethod(Runtime.java:683) com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:13) android.app.Activity.performCreate(Activity.java:6237) android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) android.app.ActivityThread.-wrap11(ActivityThread.java) android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) android.os.Handler.dispatchMessage(Handler.java:102) android.os.Looper.loop(Looper.java:148) android.app.ActivityThread.main(ActivityThread.java:5417) java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
And then comes my permission denied catch console comment. Same happens on Android N and Android M emulators. There's no other plugin running at the current view, where I ask these permissions.