You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The Camera module in Android doesn't handle pemissions for you #2813
Did you verify this is a real problem by searching [Stack Overflow]
Yep!
Tell us about the problem
Using the Camera plugin on Android N requires permissions updates. Currently this requires using another plugin, nativescript-permissions, but this should be baked into the Camera code itself.
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
CLI: 2.3.0
Cross-platform modules: 2.3.0
Runtime(s): 2.3.0
Plugin(s):
Please tell us how to recreate the issue in as much detail as possible.
Try to use the Camera on Android (most recent version).
From what I skimmed through the camera module in the core-modules isn't handling any runtime permissions which is going to cause headaches for onboarding devs with no native android experience, even more so those coming from a pre-lollipop android world. IMO - moving the camera into an external plugin from the NS team would be ideal so the manifest doesn't add the Camera permission by default unless the camera plugin is installed by the developer.
Even after explicitly granted permissions with the code below the error is still thrown.
permissions.requestPermission(["android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.CAMERA"], "I need these permissions because I'm cool")
.then(function() {
console.log("Woo Hoo, I have the power!");
})
.catch(function() {
console.log("Uh oh, no permissions - plan B time!");
});
Yes, it is related to the permission changes in 7. We are now moving the camera module in a separate plugin and will release it next week in order to provide a clean solution for the problem.
We've just finished (initial) work on native plugin for using device camera hardware. We have some issues to publish it to npm (there is a plugin with the same name :-(). We will try to get it - in case we succeed we will publish it like nativescript-camera. In worst case scenario we should change the name of the plugin which will not affect working code just some references. However you could use the current version of the plugin from its github repo. Within this repo there is an example how to use it (be aware that you will need latest tns-core-modules and tns-core-modules-widgets a.k.a. next. In order to produce package just run create.sh script from plugin root folder.
We added a special method to nativescript-camera plugin called requestPermissions() which should be called to request camera and write to external storage permissions (required to be able to share image on Google Photos). NativeScript-Camera plugin adds necessary uses-permission clauses on app prepare stage.
P.S. I'll close the issue, feel free to reopen it if needed.
Activity
bradmartin commentedon Sep 28, 2016
From what I skimmed through the camera module in the core-modules isn't handling any runtime permissions which is going to cause headaches for onboarding devs with no native android experience, even more so those coming from a pre-lollipop android world. IMO - moving the camera into an external plugin from the NS team would be ideal so the manifest doesn't add the Camera permission by default unless the camera plugin is installed by the developer.
NickIliev commentedon Sep 29, 2016
I can confirm that the camera module is not working in Android 7.
At my side, the error stack returns the following when trying to take a picture.
Even after explicitly granted permissions with the code below the error is still thrown.
Probably related to https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/camera/camera.android.ts#L39 and this thread
cfjedimaster commentedon Sep 29, 2016
That's the error I got as well. If you edit your Android manifest to target 23 it seems to correct it.
valentinstoychev commentedon Sep 29, 2016
Yes, it is related to the permission changes in 7. We are now moving the camera module in a separate plugin and will release it next week in order to provide a clean solution for the problem.
Thanks for the heads up!
nsndeck commentedon Oct 5, 2016
Hi all,
We've just finished (initial) work on native plugin for using device camera hardware. We have some issues to publish it to npm (there is a plugin with the same name :-(). We will try to get it - in case we succeed we will publish it like
nativescript-camera. In worst case scenario we should change the name of the plugin which will not affect working code just some references. However you could use the current version of the plugin from its github repo. Within this repo there is an example how to use it (be aware that you will need latesttns-core-modulesandtns-core-modules-widgetsa.k.a. next. In order to produce package just runcreate.shscript from plugin root folder.Let me know if you need some other assistance.
Nedyalko
nsndeck commentedon Oct 10, 2016
We added a special method to
nativescript-cameraplugin calledrequestPermissions()which should be called to request camera and write to external storage permissions (required to be able to share image on Google Photos). NativeScript-Camera plugin adds necessaryuses-permissionclauses on app prepare stage.P.S. I'll close the issue, feel free to reopen it if needed.
lock commentedon Aug 28, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.