Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FlutterMain.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.view;
6
7import android.content.Context;
8import android.os.Handler;
9import androidx.annotation.NonNull;
10import androidx.annotation.Nullable;
11import io.flutter.FlutterInjector;
12import io.flutter.embedding.engine.loader.FlutterLoader;
13
14/**
15 * A legacy class to initialize the Flutter engine.
16 *
17 * @deprecated Replaced by {@link io.flutter.embedding.engine.loader.FlutterLoader}.
18 */
19@Deprecated
20public class FlutterMain {
21
22 public static class Settings {
23 private String logTag;
24
25 @Nullable
26 public String getLogTag() {
27 return logTag;
28 }
29
30 /**
31 * Set the tag associated with Flutter app log messages.
32 *
33 * @param tag Log tag.
34 */
35 public void setLogTag(String tag) {
36 logTag = tag;
37 }
38 }
39
40 /**
41 * Starts initialization of the native system.
42 *
43 * @param applicationContext The Android application context.
44 */
45 public static void startInitialization(@NonNull Context applicationContext) {
46 FlutterInjector.instance().flutterLoader().startInitialization(applicationContext);
47 }
48
49 /**
50 * Starts initialization of the native system.
51 *
52 * <p>This loads the Flutter engine's native library to enable subsequent JNI calls. This also
53 * starts locating and unpacking Dart resources packaged in the app's APK.
54 *
55 * <p>Calling this method multiple times has no effect.
56 *
57 * @param applicationContext The Android application context.
58 * @param settings Configuration settings.
59 */
60 public static void startInitialization(
61 @NonNull Context applicationContext, @NonNull Settings settings) {
62 FlutterLoader.Settings newSettings = new FlutterLoader.Settings();
63 newSettings.setLogTag(settings.getLogTag());
64 FlutterInjector.instance().flutterLoader().startInitialization(applicationContext, newSettings);
65 }
66
67 /**
68 * Blocks until initialization of the native system has completed.
69 *
70 * <p>Calling this method multiple times has no effect.
71 *
72 * @param applicationContext The Android application context.
73 * @param args Flags sent to the Flutter runtime.
74 */
75 public static void ensureInitializationComplete(
76 @NonNull Context applicationContext, @Nullable String[] args) {
77 FlutterInjector.instance()
78 .flutterLoader()
79 .ensureInitializationComplete(applicationContext, args);
80 }
81
82 /**
83 * Same as {@link #ensureInitializationComplete(Context, String[])} but waiting on a background
84 * thread, then invoking {@code callback} on the {@code callbackHandler}.
85 */
87 @NonNull Context applicationContext,
88 @Nullable String[] args,
89 @NonNull Handler callbackHandler,
90 @NonNull Runnable callback) {
91 FlutterInjector.instance()
92 .flutterLoader()
93 .ensureInitializationCompleteAsync(applicationContext, args, callbackHandler, callback);
94 }
95
96 @NonNull
97 public static String findAppBundlePath() {
98 return FlutterInjector.instance().flutterLoader().findAppBundlePath();
99 }
100
101 @Deprecated
102 @Nullable
103 public static String findAppBundlePath(@NonNull Context applicationContext) {
104 return FlutterInjector.instance().flutterLoader().findAppBundlePath();
105 }
106
107 /**
108 * Returns the file name for the given asset. The returned file name can be used to access the
109 * asset in the APK through the {@link android.content.res.AssetManager} API.
110 *
111 * @param asset the name of the asset. The name can be hierarchical
112 * @return the filename to be used with {@link android.content.res.AssetManager}
113 */
114 @NonNull
115 public static String getLookupKeyForAsset(@NonNull String asset) {
116 return FlutterInjector.instance().flutterLoader().getLookupKeyForAsset(asset);
117 }
118
119 /**
120 * Returns the file name for the given asset which originates from the specified packageName. The
121 * returned file name can be used to access the asset in the APK through the {@link
122 * android.content.res.AssetManager} API.
123 *
124 * @param asset the name of the asset. The name can be hierarchical
125 * @param packageName the name of the package from which the asset originates
126 * @return the file name to be used with {@link android.content.res.AssetManager}
127 */
128 @NonNull
129 public static String getLookupKeyForAsset(@NonNull String asset, @NonNull String packageName) {
130 return FlutterInjector.instance().flutterLoader().getLookupKeyForAsset(asset, packageName);
131 }
132}
static String getLookupKeyForAsset(@NonNull String asset)
static String findAppBundlePath()
static void ensureInitializationCompleteAsync( @NonNull Context applicationContext, @Nullable String[] args, @NonNull Handler callbackHandler, @NonNull Runnable callback)
static void ensureInitializationComplete( @NonNull Context applicationContext, @Nullable String[] args)
static String getLookupKeyForAsset(@NonNull String asset, @NonNull String packageName)
static void startInitialization(@NonNull Context applicationContext)
static String findAppBundlePath(@NonNull Context applicationContext)
static void startInitialization( @NonNull Context applicationContext, @NonNull Settings settings)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback