• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Flag_grant_read_uri_permission

emnaki

Lurker
Jul 13, 2009
4
0
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:
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Uri u = Text.CONTENT_URI3; // content://com.test/text/1
        setResult(1, new Intent().setData(u).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION));
    }
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?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones