read asset folder files of another package

2019-03-06 19:43发布

问题:

I have two android applications using the same android:sharedUserId Say Application A & Application B.

Is there a way to read the contents of asset folder of B from A?

回答1:

You should not need android:sharedUserId (and unless you really know what you're doing, using android:sharedUserId is risky). Last I checked, assets are world-readable; any app can read another app's assets.

You should be able to call createPackageContext() to get a Context associated with the other app, then use getAssets() as normal to get an AssetManager from that Context.