Protecting components with custom permissions
The Android platform defines a set of default permissions, which are used to secure system services and application components. Largely, these permissions work in the most generic case, but often when sharing bespoke functionality or components between applications it will require a more tailored use of the permissions framework. This is facilitated by defining custom permissions.
This recipe demonstrates how you can define your own custom permissions.
How to do it…
Let's get started!
Before adding any custom permissions, you need to declare string resources for the permission labels. You can do this by editing the
strings.xml
file in your application project folder underres/values/strings.xml
:<string name="custom_permission_label">Custom Permission</string>.
Adding normal protection-level custom permissions to your application can be done by adding the following lines to your
AndroidManifest.xml
file:<permission android:name="android...