How can one create two Android apps where app "A" creates files and only app "B" can read the files? At first glance, Context.grantUriPermission seems like the trick because it allows restricting access to certain packages like so:
//grant permision for app with package "packageName", eg. before starting other app via intent
context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
(The above is from "How to use support FileProvider for sharing content to other apps?")
Unfortunately, anyone can create an app with a given package name. Therefore this method of restricting is not very secure.
Is there a more secure method for restricting file access? Perhaps by retrieving the public-key certificate of the calling application (app "B" in this case)?