Question

I have implemented a content provider for sharing data between two applications. Lets name them app A and App B. App A has provider tag defined as below :

<provider
        android:name="com.*.*.utility.PrinterContentProvider"
        android:authorities="com.*.*.utility"
        android:enabled="true"
        android:exported="true"
        android:readPermission="com.*.*.view.LOGIN_PERM" 
        android:writePermission="com.*.*.view.LOGIN_PERM_WRITE"
        android:grantUriPermissions="true"
       >
    </provider>

with permission given as below :

<permission android:name="com.*.*.view.LOGIN_PERM"
            android:protectionLevel="normal"
            android:description="@string/app_name"
            android:label="@string/app_name"/>
<permission android:name="com.*.*.view.LOGIN_PERM_WRITE"
            android:protectionLevel="normal"
            android:description="@string/app_name"
            android:label="@string/app_name"/>

App B has usage permission as given below for accessing content provider:

<uses-permission android:name="com.*.*.view.LOGIN_PERM"/>
<uses-permission android:name="com.*.*.view.LOGIN_PERM_WRITE"/>

and a custom permission as given below:

<permission android:name="cx.hell.andriod.pdfview.PDFVIEW_PERM"
            android:protectionLevel="normal"
            android:description="@string/app_name"
            android:label="@string/app_name"/>

App B uses this permission:

<activity android:name=".OpenFileActivity" android:label="@string/app_name"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar"
        android:permission="cx.hell.andriod.pdfview.PDFVIEW_PERM"
        android:exported="true">

If First App A is installed and then App B is installed, App A launches App B's OpenFileActivity. At this point a security exception is thrown.

Permission denied for cx.hell.andriod.pdfview.PDFVIEW_PERM

App A has uses permission defined in manifest for cx.hell.andriod.pdfview.PDFVIEW_PERM Still it throws an exception .....

Update (Exception logcat):

04-15 09:04:17.184: W/ActivityManager(488): Permission Denial: starting Intent { act=cx.hell.andriod.pdfview.OPENFILEACTIVITY dat=file:///storage/sdcard0/Invoice.pdf typ=application/pdf cmp=cx.hell.android.pdfview/.OpenFileActivity (has extras) } from ProcessRecord{4222ab80 3173:com.tcs.infiniti.view/u0a128} (pid=3173, uid=10128) requires cx.hell.andriod.pdfview.PDFVIEW_PERM
04-15 09:04:17.194: W/System.err(3173): java.lang.SecurityException: Permission Denial: starting Intent { act=cx.hell.andriod.pdfview.OPENFILEACTIVITY dat=file:///storage/sdcard0/Invoice.pdf typ=application/pdf cmp=cx.hell.android.pdfview/.OpenFileActivity (has extras) } from ProcessRecord{4222ab80 3173:com.tcs.infiniti.view/u0a128} (pid=3173, uid=10128) requires cx.hell.andriod.pdfview.PDFVIEW_PERM

Solution:

Found a solution to this problem after numerous trials and errors by just changing permission protection level form normal to signature.

Was it helpful?

Solution

In App A Manifest xml file you need to add the following Line

 <uses-permission android:name="cx.hell.andriod.pdfview.PDFVIEW_PERM"/>

Add a intent-filter to your activity tag for Openfileactivity, something like this

        <intent-filter >
            <action android:name="cx.hell.android.NewAction" />
            <category android:name="android.intent.category.DEFAULT" />                
        </intent-filter>

And atlast while Launching the Activity use the above intent-filter name as a setaction for intent object,

            Intent in = new Intent();
            in.setAction("cx.hell.android.NewAction");
            in.addCategory("android.intent.category.DEFAULT");
            startActivity(in);

Now you can launch your Activity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top