I am trying to read the content from a cursor like so:
cursor = context.getContentResolver().query(TASKS_URI, null, null, new String[]{"-1", "true"}, null);
Where the TASKS_URI is:
private final static Uri TASKS_URI = Uri.parse("content://org.dayup.gtask.data/tasks");
So all i am trying to do is to get a cursor from another app.
In my manifest.xml i define my permission as:
<uses-permission android:name="org.dayup.gtask.permission.READ_TASKS"/>
The problem is that if my app was installed before the other app (in this case gtask) i get the following error:
05-08 15:26:45.380: ERROR/ActivityThread(18564): Failed to find provider info for org.dayup.gtask.key
05-08 15:26:45.390: ERROR/AndroidRuntime(18509): FATAL EXCEPTION: Thread-12
java.lang.SecurityException: Permission Denial: reading org.dayup.gtask.GoogleTaskProvider uri content://org.dayup.gtask.data/tasks from pid=18509, uid=10114 requires org.dayup.gtask.permission.READ_TASKS
at android.os.Parcel.readException(Parcel.java:1322)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:372)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:408)
at android.content.ContentResolver.query(ContentResolver.java:264)
If i reinstall my app or my app was installed after the other apps everything works fine.
Any idea on how to reacquire these permissions on runtime ?
There is a workaround for this.
The trick is to define the permissions as if they were your own.
Here is an example: