SecurityException with grantUriPermission when sharing a file with FileProvider

后端 未结 2 755
甜味超标
甜味超标 2020-12-03 07:56

I have two applications. I\'m trying to share a file from application A to application B using a FileProvider. Application A calls the insert method on a ContentProvider i

2条回答
  •  有刺的猬
    2020-12-03 08:33

    Well, after a week and a lot of trial and error, it seems the answer is to not specify permissions. So the App A Manifest should instead contain:

    
        
    
    

    ie, I removed the read and write permissions. My initial understanding, and failing to find documentation that said otherwise, was these were necessary to restrict access. However, I've found they actually interfere and cause Context.grantUriPermission to fail. Access is limited already.

    To complete the picture, and answer the second part of my question, I found the following:

    Android Permission denial in Widget RemoteViewsFactory for Content

    I had to add:

    final long token = Binder.clearCallingIdentity();
    try {
        [retrieve file here]
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    

    to the Content Provider in App B. Otherwise it would get security errors as well.

提交回复
热议问题