I am trying to get an update ANE (Adobe native extension) to work with my Adobe AIR application on Android and it looks like I can't get the correct FILE_PROVIDER_PATHS for the files.
I download the file to the File.applicationStorageDirectory of the app in my Adobe Flex App.
My FileProvider in the Android manifest looks like this:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="air.MY_APP_ID_HERE.files"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileproviderpaths" />
</provider>
fileproviderpaths.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="." />
<external-path name="files" path="." />
<external-files-path name="files" path="." />
</paths>
And then in the ANE (Java) code I am trying to access the file like this:
newFile = new File(urlString);
// newFile.getPath() debugs as "/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk"
// the file really exists there - i see it on newFile.exists() and newFile.length()
// context.getActivity() just returns the Android Context - this is Adobe AIR specific
// context.getActivity().getPackageName() debugs as "air.MY_APP_ID_HERE"
Uri fileUri = FileProvider.getUriForFile(context.getActivity(), context.getActivity().getPackageName() + ".files", newFile);
No matter what I try in the fileproviderpaths.xml I am always getting an exception
Failed to find configured root that contains /data/data/air.MYAPP_ID_HERE/MYAPP_ID_HERE/Local Store/myFileName.apk
Now my main question is why it is called "/data/user/0/air.MY_APP_ID_HERE..." in the newFile.getPath() and "/data/data/air.MYAPP_ID_HERE..." in the FileProvider exception?
The second question is how do I reach the "/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk" with the Fileprovider or how do I set the paths in the fileproviderpaths.xml for it
Thank you for your time!
Phew, it took a lot of trial and errors but I have finally figured it out. The solution was close though.
So when we create a file in Flex / AIR like this
_updateDirectory = File.applicationStorageDirectory;
_updateFile = _updateDirectory.resolvePath("myFileName.apk");
the native path on the Android device points to this location (you can debug it in Flex under _updateFile.nativePath)
/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/Local Store/myFileName.apk
in the fileproviderpaths.xml you need to specify the file-path, the other two are not necessary. But this
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="somenamehere" path="." />
</paths>
points to this directory on the device:
/data/user/0/air.MY_APP_ID_HERE/files
So what we need to do is to go one directory up to the root and then down to our AIR applicationStorageDirectory:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="somenamehere" path="../MY_APP_ID_HERE/Local Store" />
</paths>
and then you can pass that file to the Java ANE (in my case I have downloaded the file in Flex and want to let the ANE install it):
AppInstaller.getInstance().installApp(_updateFile.nativePath);
The Java ANE code:
urlString = Uri.parse(args[0].getAsString()).toString();
newFile = new File(urlString);
Uri fileUri = FileProvider.getUriForFile(context.getActivity(), context.getActivity().getPackageName() + ".files", newFile);
The + ".files" part here refers to the fileprovider declaration in the manifest
android:authorities="air.MY_APP_ID_HERE.files"
So ".files" here and ".files" there should be called the same, And make sure you add the "air." before your actual app id, because that is how your app will be installed on the device - as "air.YOU_APP_ID_HERE"