1. Check out our companion app, Forums for Android! Download from Google Play


Discussion in 'Application Development' started by emnaki, Jul 28, 2009.

  1. emnaki

    emnaki New Member
    Thread Starter

    Jul 13, 2009
    I don't understand how to use this to do URI based permissions on a restricted Content Provider.

    Here is what I did (did not work):

    1. made an Activity (GrantAccess) in the same application as the Content Provider with access to it. Only important code is this:

    Code (Text):
    2. public void onCreate(Bundle savedInstanceState) {
    3.         super.onCreate(savedInstanceState);
    4.         Uri u = Text.CONTENT_URI3; // content://com.test/text/1
    5.         setResult(1, new Intent().setData(u).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION));
    6.     }
    All it does is put the uri into the intent and set the FLAG_GRANT_READ_URI_PERMISSION. returning the intent to the calling activity.

    2. From an activity with no access to the Content Provider, use startActivityForResult to invoke the above activity (GrantAccess) and have an onActivityResult method to get back the intent.

    Now I am stuck. I want to use the uri inside the intent returned to query the content provider but I don't know how to do it. Getting the uri from the intent with getData() method and using it in the resolver's query gives denied access error. Does anyone know how to do this?


Share This Page