Issue
I am trying to write an Android Native program using NDK that will access camera from the native code. But to access the camera I need permission even for native code. I found a sample provided by google to access camera from the native code but it checks the permission by calling a Java method written in the activity [ref]. Is there any way to check for the permission form the native code only, without extending the NativeActivity
[ref]? Possibly not even accessing the Dalvik VM at all (which I believe will give me a better performance)
Solution
There is an easy way to check whether the permission was granted: try to open the camera device, and it will fail, or succeed.
To request the permission, you must use framework API explicitly. There is no C API for requestPermissions() or her alternatives (that's to answer “Possibly not even accessing the Dalvik VM”).
Note that you can avoid permissions request: you can instruct your user to grant the permission in System Settings for your App (no, I am not endorsing this approach, but if you have some special reason to not extend NativeActivity and have no Java code in your APK, you still can.
Answered By - Alex Cohn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.