Android Custom Permissions

Google encourages developers to define custom permissions to protect our publicly available activities and custom data providers.  The first step is to define such permissions in your manifest so that your app as well as all other apps can display pretty text for the permissions.  Apps that merely use your custom permissions will display the text you defined in your app for each permission. One issue I discovered is that you should never define the permission group as an empty string (android:permissionGroup=””) or else the permission definition becomes invalid and no other app will be able to use it.

Custom permissions should also define a custom Permission Group if they are not part of one of the Android built-in groups, otherwise they will be displayed as part of a permission called “Default” and all your custom permissions will be shown as a comma separated list underneath it. For example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mydomain.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <permission-group android:name="com.mydomain.provider.permissions" 
        android:label="@string/perm_text_group_mydomain_provider" />

    <permission android:name="com.mydomain.provider.permission.ACCESS_DATA"
        android:permissionGroup="com.mydomain.provider.permissions" 
        android:label="@string/perm_text_access_mydomain_provider" />

    <permission android:name="com.mydomain.provider.permission.WRITE_DATA"
        android:permissionGroup="com.mydomain.provider.permissions" 
        android:label="@string/perm_text_modify_mydomain_provider" />

    <uses-permission android:name="com.mydomain.provider.permission.ACCESS_DATA" />
    <uses-permission android:name="com.mydomain.provider.permission.WRITE_DATA" />

    <application
      android:label="@string/app_name"
      android:description="@string/app_desc" 
      android:icon="@drawable/app_icon" >

        <provider android:name="com.mydomain.MyProvider" 
            android:authorities="com.mydomain.provider.myprovider" 
            android:readPermission="com.mydomain.provider.permission.ACCESS_DATA" 
            android:writePermission="com.mydomain.provider.permission.WRITE_DATA" 
            android:exported="true" >
        </provider>

    </application>

</manifest>

Once you have defined all your permissions, other apps can simply use them with <uses-permission> and their apps will use your string definitions when displaying them in Settings as part of managing the device’s apps.

File Browser Intents and Providers

I have finally put together a comprehensive list of Intents and Providers published by my File Browser app. You can find that list over on the File Browser Intents & Providers page.

As a convenience, I will post what is currently listed there:
Intent & Provider List

  1. Pick File
  2. Pick Multiple Files
  3. Pick Folder
  4. Save To New File
  5. Save To New Folder
  6. Playlist Creator
  7. Create Zip File
  8. Unpack Zip File
  9. MIME Type Provider

 

Android: Using Blackmoon File Browser’s MIME type provider

The function I use to translate a filename and given extension into it’s MIME type is available as a Provider in BmFB so that you can use my work for your app too.

    Uri theContentProvider = Uri.parse("content://com.blackmoonit.android.mimetypeprovider/getMIMEtype");
    Uri theContentTypeRequest = Uri.withAppendedPath(theContentProvider, aFile.getName());
    Cursor theTypeResult = managedQuery(theContentTypeRequest, null, null, null, null);
    theTypeResult.moveToFirst();
    if (!theTypeResult.isNull(0)) {
        String theMIMEType = theTypeResult.getString(0);
        ...
    }