Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 2.3 KB

Permissions.md

File metadata and controls

60 lines (48 loc) · 2.3 KB

CWAC-Cam2 and Permissions

Courtesy of Android Studio's manifest merger process, this library will automatically add some permissions to your app's manifest:

  • CAMERA
  • WRITE_EXTERNAL_STORAGE
  • RECORD_AUDIO

Most apps using this library will need these permissions. However, there are other considerations you may need to take into account for your apps with respect to permissions.

Android 6.0 Runtime Permissions

On Android 6.0, all three of the permissions listed above are considered dangerous permissions and therefore are subject to the new runtime permission system. That means that not only do you need the <uses-permission> element in the manifest for the permission, but you need to ask the user for the permission at runtime, until the user grants it (or tells you to stop asking).

The library will handle some bare-bones work related to this, asking the user for CAMERA and RECORD_AUDIO. However, really, this logic should be in the app, not the library, as you will need to deal with the cases where the user declines the permission (the library just finishes its activity and returns control to you).

This documentation is not designed to provide complete instructions for using the runtime permission system. Please refer to the official documentation or the author's book for more details.

The demo app implements a fairly rudimentary check for runtime permissions. The demo-playground app has targetSdkVersion set to 22, to demonstrate a "legacy" app using the library.

Blocking Permissions

If you do not intend to take videos, you could get away without the RECORD_AUDIO and perhaps the WRITE_EXTERNAL_STORAGE permissions (depending on where you are saving the photos). To remove those from your app's manifest, add the following elements to your manifest, as children of the root <manifest> element:

<uses-permission
    android:name="android.permission.RECORD_AUDIO"
    tools:node="remove"/>
<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    tools:node="remove"/>

This tells the manifest merger process that while one or more libraries might be asking for these permissions, block them from the app's manifest generated by the merger.