0

My plan is to have a main app that uses the raw files from a different app. The main app will handle all the data, and the other app acts as a sort of DLC. When the other app is run, it will open the main app with its own SharedPreferences, and set it so that the main app can read the raws from the other app.

Is the reading of the raws (not the implementation of SharedPreferences) possible if the other app was somehow forced closed?

jmoerdyk
  • 5,544
  • 7
  • 38
  • 49

1 Answers1

0

Yeah, I believe you should be able to do this through the PackageManager and Resources APIs. I've done this with Strings and Drawables, so I don't know of any particular reason it wouldn't work with raw resources.

try {
    Resources res = getPackageManager().getResourcesForApplication("other.package.name");
    int resourceId = res.getIdentifier("name_of_raw_resource", "raw", "other.package.name");
    if (resourceId != 0) {
        InputStream rawFile = res.openRawResource(resourceId);
    } else {
        // Raw resource was not found
    }
} catch (PackageManager.NameNotFoundException e) {
    // App is not installed
}
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274