|
9 | 9 | import android.support.annotation.NonNull; |
10 | 10 |
|
11 | 11 | import io.flutter.embedding.engine.FlutterEngine; |
| 12 | +import io.flutter.embedding.engine.loader.FlutterLoader; |
12 | 13 | import io.flutter.plugin.common.BinaryMessenger; |
13 | 14 | import io.flutter.plugin.platform.PlatformViewRegistry; |
14 | 15 | import io.flutter.view.TextureRegistry; |
@@ -101,19 +102,22 @@ class FlutterPluginBinding { |
101 | 102 | private final BinaryMessenger binaryMessenger; |
102 | 103 | private final TextureRegistry textureRegistry; |
103 | 104 | private final PlatformViewRegistry platformViewRegistry; |
| 105 | + private final FlutterAssets flutterAssets; |
104 | 106 |
|
105 | 107 | public FlutterPluginBinding( |
106 | 108 | @NonNull Context applicationContext, |
107 | 109 | @NonNull FlutterEngine flutterEngine, |
108 | 110 | @NonNull BinaryMessenger binaryMessenger, |
109 | 111 | @NonNull TextureRegistry textureRegistry, |
110 | | - @NonNull PlatformViewRegistry platformViewRegistry |
| 112 | + @NonNull PlatformViewRegistry platformViewRegistry, |
| 113 | + @NonNull FlutterAssets flutterAssets |
111 | 114 | ) { |
112 | 115 | this.applicationContext = applicationContext; |
113 | 116 | this.flutterEngine = flutterEngine; |
114 | 117 | this.binaryMessenger = binaryMessenger; |
115 | 118 | this.textureRegistry = textureRegistry; |
116 | 119 | this.platformViewRegistry = platformViewRegistry; |
| 120 | + this.flutterAssets = flutterAssets; |
117 | 121 | } |
118 | 122 |
|
119 | 123 | @NonNull |
@@ -146,5 +150,47 @@ public TextureRegistry getTextureRegistry() { |
146 | 150 | public PlatformViewRegistry getPlatformViewRegistry() { |
147 | 151 | return platformViewRegistry; |
148 | 152 | } |
| 153 | + |
| 154 | + @NonNull |
| 155 | + public FlutterAssets getFlutterAssets() { |
| 156 | + return flutterAssets; |
| 157 | + } |
149 | 158 | } |
| 159 | + |
| 160 | + /** |
| 161 | + * Provides Flutter plugins with access to Flutter asset information. |
| 162 | + */ |
| 163 | + interface FlutterAssets { |
| 164 | + /** |
| 165 | + * Returns the relative file path to the Flutter asset with the given name, including the file's |
| 166 | + * extension, e.g., {@code "myImage.jpg"}. |
| 167 | + * |
| 168 | + * <p>The returned file path is relative to the Android app's standard assets directory. |
| 169 | + * Therefore, the returned path is appropriate to pass to Android's {@code AssetManager}, |
| 170 | + * but the path is not appropriate to load as an absolute path. |
| 171 | + */ |
| 172 | + String getAssetFilePathByName(@NonNull String assetFileName); |
| 173 | + |
| 174 | + /** |
| 175 | + * Same as {@link #getAssetFilePathByName(String)} but with added support for an explicit |
| 176 | + * Android {@code packageName}. |
| 177 | + */ |
| 178 | + String getAssetFilePathByName(@NonNull String assetFileName, @NonNull String packageName); |
| 179 | + |
| 180 | + /** |
| 181 | + * Returns the relative file path to the Flutter asset with the given subpath, including the file's |
| 182 | + * extension, e.g., {@code "/dir1/dir2/myImage.jpg"}. |
| 183 | + * |
| 184 | + * <p>The returned file path is relative to the Android app's standard assets directory. |
| 185 | + * Therefore, the returned path is appropriate to pass to Android's {@code AssetManager}, |
| 186 | + * but the path is not appropriate to load as an absolute path. |
| 187 | + */ |
| 188 | + String getAssetFilePathBySubpath(@NonNull String assetSubpath); |
| 189 | + |
| 190 | + /** |
| 191 | + * Same as {@link #getAssetFilePathBySubpath(String)} but with added support for an explicit |
| 192 | + * Android {@code packageName}. |
| 193 | + */ |
| 194 | + String getAssetFilePathBySubpath(@NonNull String assetSubpath, @NonNull String packageName); |
| 195 | + } |
150 | 196 | } |
0 commit comments