fix asset:// URIs on Android
This commit is contained in:
@@ -98,20 +98,24 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
|
|||||||
if(path!!.startsWith("file://")) {
|
if(path!!.startsWith("file://")) {
|
||||||
data = File(path!!.substring(6)).readBytes()
|
data = File(path!!.substring(6)).readBytes()
|
||||||
} else {
|
} else {
|
||||||
|
var assetPath = path
|
||||||
|
if(assetPath.startsWith("asset://")) {
|
||||||
|
assetPath = assetPath!!.substring(8)
|
||||||
|
}
|
||||||
val loader = FlutterInjector.instance().flutterLoader()
|
val loader = FlutterInjector.instance().flutterLoader()
|
||||||
val key = loader.getLookupKeyForAsset(path)
|
val key = loader.getLookupKeyForAsset(assetPath)
|
||||||
val hotReloadPath = HotReloadPathHelper.getAssetPath(key, activity.getPackageName())
|
val hotReloadPath = HotReloadPathHelper.getAssetPath(key, activity.getPackageName())
|
||||||
if (hotReloadPath != null) {
|
if (hotReloadPath != null) {
|
||||||
data = File(hotReloadPath).readBytes()
|
data = File(hotReloadPath).readBytes()
|
||||||
} else {
|
} else {
|
||||||
Log.i("polyvox_filament", "Loading resource from main asset bundle")
|
Log.i("polyvox_filament", "Loading resource from main asset bundle at ${assetPath}")
|
||||||
|
|
||||||
val assetManager: AssetManager = activity.assets
|
val assetManager: AssetManager = activity.assets
|
||||||
try {
|
try {
|
||||||
data = assetManager.open(key).readBytes()
|
data = assetManager.open(key).readBytes()
|
||||||
Log.i("polyvox_filament", "Loaded ${data.size} bytes")
|
Log.i("polyvox_filament", "Loaded ${data.size} bytes")
|
||||||
} catch (e:Exception) {
|
} catch (e:Exception) {
|
||||||
Log.e("polyvox_filament", "Failed to open asset at ${path}", null)
|
Log.e("polyvox_filament", "Failed to open asset at ${assetPath}", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user