Share raw resource between apk's

后端 未结 2 662
既然无缘
既然无缘 2020-12-18 14:15

I have an apk (App1) that has a raw resource (res/raw/mytextfile.txt) and I would like to read that text file from another apk (App2). I define a content provider in App1 a

相关标签:
2条回答
  • 2020-12-18 14:51

    I have an APK that reads drawables from another of my APK.

    To do so, I have set the following fields in the manifest file for both projects:

    android:sharedUserId="com.myapp.shareduserid"
    android:process="com.myapp.process"
    

    Replace the com.myapp.shareduserid and com.myapp.process by your own values. This will allow both the APK to access data from each other.

    Once that is done you can use something similar to the sample I am providing here. Most likely you can do the same with raw. The example here uses drawables:

    mApk1Context = createPackageContext("com.apk1.app",Context.CONTEXT_IGNORE_SECURITY);
    mApk1Resources = mApk1Context.getResources();
    mDrawableResID = mApk1Resources.getIdentifier("mypng", "drawable","com.apk1.app");
    Drawable myDrawable = mAndromedaAddonResources.getDrawable( mDrawableResID );
    if( myDrawable != null )
        ((ImageView) findViewById(R.id.mywindow)).setBackgroundDrawable(myDrawable );
    

    Replace com.apk1.app by your own package name.

    0 讨论(0)
  • 2020-12-18 15:13

    there is no way to do that as Android Library Projects cannot have raw assets.

    0 讨论(0)
提交回复
热议问题