Bungles
Bungles

Reputation: 2247

How can I find and access the play store asset package for my Android app?

My Android game has an install-time asset pack with all the graphics in it. This isn't stored stored in my app's primary package so I can't access it with getPackageResourcePath(). Is there some other function that would allow me to get the asset package in the same way?

Upvotes: 0

Views: 79

Answers (1)

Bungles
Bungles

Reputation: 2247

I found the solution for what I was trying to do.

// Get path to play store assets
val pkgInfo = packageManager.getPackageInfo("com.mycompany.mygame", 0)
var playAssetsPath = ""
val splitNames = pkgInfo.splitNames
for (idx in 0..splitNames.size - 1) {
    if (splitNames[idx] == "play_assets") {
        val splitsPaths = pkgInfo.applicationInfo?.splitSourceDirs
        playAssetsPath = splitsPaths!![idx]
    }
}
Log.e(LOGTAG, "playAssetsPath = $playAssetsPath")

With this full APK path I can access my assets without relying upon AssetManager's clunky streaming mechanism, which doesn't recognize directory structures.

Upvotes: 0

Related Questions