Android Permission denial in Widget RemoteViewsFactory for Content

后端 未结 3 2070
太阳男子
太阳男子 2020-12-15 08:09

I have a widget which I am trying to use to display information from my app\'s local database inside of a listview.

I\'m using the RemoteViewsService.RemoteViewsFact

3条回答
  •  爱一瞬间的悲伤
    2020-12-15 08:19

    This is happening because RemoteViewsFactory is being called from a remote process, and that context is being used for permission enforcement. (The remote caller doesn't have permission to use your provider, so it throws a SecurityException.)

    To solve this, you can clear the identity of the remote process, so that permission enforcement is checked against your app instead of against the remote caller. Here's a common pattern you'll find across the platform:

    final long token = Binder.clearCallingIdentity();
    try {
        [perform your query, etc]
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    

提交回复
热议问题