I’m creating an app which I would like to not speak about what it is right now, but you have to select an APK. Now when I get the Result URI from the Activity Starter after picking the APK, I get content://com.android.providers.downloads.documents/document/1332. I’m wondering how I can make this into a path that I can get the APK from and upload it to something.
Permission list from APK via Path
This is basically an extension from what’s above, when they select their APK file, I would like it to get the apps permissions using GetPackageArchiveInfo(path, PackageManager.GET_PERMISSIONS), but I don’t know how to return it as a readable list as a string.
I don't believe that it is possible to translate this into a file URI as content URIs are not guaranteed to exist in the file system at all. It's possible there is a way to do this in Android, but it escapes me and looking at StackOverflow might be the best opportunity to find a solution for this.
It seems like what you would want to do is the following:
Open an InputStream to the content using ContentResolver's openInputStream(Uri) method.
Create a ZipInputStream to wrap the input stream.
Locate the ZipEntry for the AndroidManifest.xml entry in the ZipInputStream and read it into a byte array.
Use something like this gist to decompress the manifest back into XML and then parse out the uses-permission tags.
Like I said in my previous post, you can use the code in the linked Gist to decompress the XML string. Then just use a regex to parse out the uses-permission tag.
It’s possible you might be able to get a file URI equivalent using this technique (although not guaranteed):