We have implemented Android M's Direct Share support in our app but getting SecurityException when we try to access content provider in our ChooserTargetService implementation. We don’t want to set “exported=true” for content provider….so seems like we need to invoke grantUriPermission(). What’s not clear, if this is the correct approach, is what package name to pass in to this (have tried various ones unsuccessfully).
Following is exception we get:
W Binder : Caught a RuntimeException from the binder stub implementation.
W Binder : java.lang.SecurityException: Permission Denial: reading <my content provider> uri <content provider uri> from pid=0, uid=1000 requires the provider be exported, or grantUriPermission()
W Binder : at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:605)
W Binder : at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:480)
W Binder : at android.content.ContentProvider$Transport.query(ContentProvider.java:211)
W Binder : at android.content.ContentResolver.query(ContentResolver.java:491)
W Binder : at android.content.ContentResolver.query(ContentResolver.java:434)
W Binder : at <my package>.MyChooserTargetService.onGetChooserTargets(MyChooserTargetService.java:66)
W Binder : at android.service.chooser.ChooserTargetService$IChooserTargetServiceWrapper.getChooserTargets(ChooserTargetService.java:147)
W Binder : at android.service.chooser.IChooserTargetService$Stub.onTransact(IChooserTargetService.java:67)
W Binder : at android.os.Binder.execTransact(Binder.java:453)