1

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!

Philarmon
  • 1,796
  • 1
  • 10
  • 14
  • `newFile = new File(urlString); ` Well what is the value of urlString? You should have started with that. Please edit your code. – blackapps Oct 09 '19 at 17:41
  • And what is the value of fileUri.toSTring() ? – blackapps Oct 09 '19 at 17:43
  • `"/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk"`. A directory `/data/user/0/air.MY_APP_ID_HERE` wil not exist i think. But i do not know air. A directory `/data/user/0/MY_APP_ID_HERE`could exist. That would be your apps private internal memory. – blackapps Oct 09 '19 at 17:46
  • The FileProvider expects the files in getFilesDir() or in subdirectories of it. What is the value of getFilesDir().getAbsolutePath() ? – blackapps Oct 09 '19 at 17:48
  • ` ` I would not give them all three the name `files`. – blackapps Oct 09 '19 at 17:50
  • urlString is adobe air specific and fileUri.toString() does not exist, because it can't find the file, this is my main problem. getFilesDir().getAbsolutePath() is "/data/user/0/air.MY_APP_ID_HERE/files". So where does this "/files" at the end come from and how do I change it to "/MY_APP_ID_HERE/LocalStore/". Which path do I need to keep for the getFilesDir() in the fileproviderpaths.xml? I actually need only one of the, right? Thank you! – Philarmon Oct 21 '19 at 08:12
  • `fileUri.toString() does not exist,` What do you mean? That compiles. And gives you a value. Now which value do you get i asked. – blackapps Oct 21 '19 at 08:28
  • `getFilesDir().getAbsolutePath() is "/data/user/0/air.MY_APP_ID_HERE/files"` I do not believe that. It will be "/data/user/0/MY_APP_ID_HERE/files" And it is pretty normal that it ends on /files. – blackapps Oct 21 '19 at 08:30
  • The "air" prefix is added by Adobe air, so assume this is my app id. I'm getting an exception when trying to create the fileURI. So "/files" at the end of getFilesDir() is the default? My file is stored under "/data/user/0/MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk" - does that mean I need to store the file in the /files subdirectory to access it? – Philarmon Oct 21 '19 at 10:00
  • Well, actually Adobe AIR ALWAYS store the file under /data/user/0/MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk, there is no way to store it under /data/user/0/air.MY_APP_ID_HERE/files ... – Philarmon Oct 21 '19 at 10:06

1 Answers1

0

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"

Philarmon
  • 1,796
  • 1
  • 10
  • 14