Provide lookup key to access Flutter assets in the APK (flutter/engine#4785)
This commit is contained in:
@@ -9,6 +9,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.*;
|
||||
import io.flutter.view.FlutterMain;
|
||||
import io.flutter.view.FlutterNativeView;
|
||||
import io.flutter.view.FlutterView;
|
||||
import io.flutter.view.TextureRegistry;
|
||||
@@ -111,6 +112,16 @@ public class FlutterPluginRegistry
|
||||
return mFlutterView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lookupKeyForAsset(String asset) {
|
||||
return FlutterMain.getLookupKeyForAsset(asset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lookupKeyForAsset(String asset, String packageName) {
|
||||
return FlutterMain.getLookupKeyForAsset(asset, packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registrar publish(Object value) {
|
||||
mPluginMap.put(pluginKey, value);
|
||||
|
||||
@@ -105,6 +105,29 @@ public interface PluginRegistry {
|
||||
*/
|
||||
FlutterView view();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the file name for the given asset.
|
||||
* The returned file name can be used to access the asset in the APK
|
||||
* through the {@link AssetManager} API.
|
||||
*
|
||||
* @param asset the name of the asset. The name can be hierarchical
|
||||
* @return the filename to be used with {@link AssetManager}
|
||||
*/
|
||||
String lookupKeyForAsset(String asset);
|
||||
|
||||
/**
|
||||
* Returns the file name for the given asset which originates from the
|
||||
* specified packageName. The returned file name can be used to access
|
||||
* the asset in the APK through the {@link AssetManager} API.
|
||||
*
|
||||
* @param asset the name of the asset. The name can be hierarchical
|
||||
* @param packageName the name of the package from which the asset originates
|
||||
* @return the file name to be used with {@link AssetManager}
|
||||
*/
|
||||
String lookupKeyForAsset(String asset, String packageName);
|
||||
|
||||
|
||||
/**
|
||||
* Publishes a value associated with the plugin being registered.
|
||||
*
|
||||
|
||||
@@ -73,7 +73,7 @@ public class FlutterMain {
|
||||
private static final String MANIFEST = "flutter.yaml";
|
||||
|
||||
private static String fromFlutterAssets(String filePath) {
|
||||
return sFlutterAssetsDir + "/" + filePath;
|
||||
return sFlutterAssetsDir + File.separator + filePath;
|
||||
}
|
||||
|
||||
private static final Set<String> SKY_RESOURCES = ImmutableSetBuilder.<String>newInstance()
|
||||
@@ -308,4 +308,30 @@ public class FlutterMain {
|
||||
File appBundle = new File(dataDirectory, sFlutterAssetsDir);
|
||||
return appBundle.exists() ? appBundle.getPath() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file name for the given asset.
|
||||
* The returned file name can be used to access the asset in the APK
|
||||
* through the {@link AssetManager} API.
|
||||
*
|
||||
* @param asset the name of the asset. The name can be hierarchical
|
||||
* @return the filename to be used with {@link AssetManager}
|
||||
*/
|
||||
public static String getLookupKeyForAsset(String asset) {
|
||||
return fromFlutterAssets(asset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file name for the given asset which originates from the
|
||||
* specified packageName. The returned file name can be used to access
|
||||
* the asset in the APK through the {@link AssetManager} API.
|
||||
*
|
||||
* @param asset the name of the asset. The name can be hierarchical
|
||||
* @param packageName the name of the package from which the asset originates
|
||||
* @return the file name to be used with {@link AssetManager}
|
||||
*/
|
||||
public static String getLookupKeyForAsset(String asset, String packageName) {
|
||||
return getLookupKeyForAsset(
|
||||
"packages" + File.separator + packageName + File.separator + asset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +254,14 @@ public class FlutterView extends SurfaceView
|
||||
return mNativeView.getPluginRegistry();
|
||||
}
|
||||
|
||||
public String getLookupKeyForAsset(String asset) {
|
||||
return FlutterMain.getLookupKeyForAsset(asset);
|
||||
}
|
||||
|
||||
public String getLookupKeyForAsset(String asset, String packageName) {
|
||||
return FlutterMain.getLookupKeyForAsset(asset, packageName);
|
||||
}
|
||||
|
||||
public void addActivityLifecycleListener(ActivityLifecycleListener listener) {
|
||||
mActivityLifecycleListeners.add(listener);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user