learner
learner

Reputation: 11780

Runtime permission before android M (api 14 and up)

Is there a way to implement runtime permission for apps that target API 14 and up? My app has a camera feature but it is not required. How do I specify this in the manifest? Right now I have

<uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>

    <uses-feature android:name="android.hardware.camera"/>
    <uses-feature android:name="android.hardware.camera2.autofocus"/>

Is there a better way of doing this?

Upvotes: 1

Views: 228

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006594

Is there a way to implement runtime permission for apps that target API 14 and up?

If you mean "hide permissions from the user at install time, and only ask for them at runtime", then the answer is no.

Is there a better way of doing this?

It's the only way of doing it and having everything be in one app.

You could implement the camera feature as a plugin with a separate APK. You would use secure IPC to communicate from the main app to the plugin (e.g., custom signature permissions or your own manual signature checks). The plugin would have the CAMERA and related permissions in its manifest; the main app would not.

On the plus side, the user does not have to agree to those permissions for the main app, and those who never install the plugin never have to worry about the permissions.

However, this does add complexity:

  • The user has to install the main app and the plugin to get the full range of functionality you presently have in just the one app

  • You have to use PackageManager and such to determine if the plugin exists and can be used

  • You have to deal with some number of people who will install the plugin without having the main app and wonder what's going on

Upvotes: 1

Related Questions