Accessing assets of other Android app on Jelly Bean
Asked Answered
F

1

3

I have a pair of Android apps. One is a free 'reader' app and the other is a paid for 'Data' app with a text file in a sub directory of its assets.

The reader app uses the following code to access the data app's text file:

Intent myIntent = new Intent("myintent");
List<ResolveInfo> dataPacks = packageManager.queryIntentActivities(myIntent, 0);
String packageName = dataPacks.get(0).activityInfo.packageName
Resources res = packageManager.getResourcesForApplication(packageName);
AssetManager assets = res.getAssets();
String[] dataFiles = assets.list("Data");

This has been working fine but apps downloaded to Jelly Bean using Google Play are not working (datafiles is empty). If the app is installed directly from email it is fine so I suspect my problem is related to the recent security changes to Google Play. However, these have allegedly been undone but I am still having problems.

Can anybody shed light on what is going wrong? (unfortunately I dont have a Jelly Bean device)

Alternatively, can somebody suggest a better mechanism for accessing the data app's txt file?

Thanks

Fibrilla answered 3/10, 2012 at 20:44 Comment(0)
B
4

Paid apps on JB devices are 'forward locked'. This means that the APK is split in two parts -- one with public resources, and one with private ones and code, which is not readable by other apps. Some details here: http://nelenkov.blogspot.com/2012/07/using-app-encryption-in-jelly-bean.html

I haven't looked into how files are split in detail, but the problem you are seeing suggests that assets are part of the private APK, which makes sense, since you typically stick API keys, etc in assets.

So you need to use a more indirect method to share info between the two apps such as a ContentProvider or remote service. Make sure you require signature permissions to access those, to make sure only your own apps can use them.

Battista answered 4/10, 2012 at 2:54 Comment(2)
Checked this yesterday. As expected, assets (/res/asset) are packaged in the private part of the APK, so you cannot access them from another app directly. You can test this on the emulator as well: you need to install using the '-l' (forward lock) option: `adb install -l myapp.apk'Battista
Thanks Nik, I've rewritten my code to use a ContentProvider instead and it is working for me.. Havent yet had chance to release into the wild and see if it fixes my original problem though.Fibrilla

© 2022 - 2024 — McMap. All rights reserved.