Skip to content

Commit 06e7528

Browse files
masewocharafau
authored andcommitted
make plugin work in headless mode when extending FlutterApplication (#578)
1 parent 0f0440b commit 06e7528

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
3232
private static final String JS_CHANNEL_NAMES_FIELD = "javascriptChannelNames";
3333

3434
public static void registerWith(PluginRegistry.Registrar registrar) {
35-
channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
36-
final FlutterWebviewPlugin instance = new FlutterWebviewPlugin(registrar.activity(), registrar.activeContext());
37-
registrar.addActivityResultListener(instance);
38-
channel.setMethodCallHandler(instance);
35+
if (registrar.activity() != null) {
36+
channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
37+
final FlutterWebviewPlugin instance = new FlutterWebviewPlugin(registrar.activity(), registrar.activeContext());
38+
registrar.addActivityResultListener(instance);
39+
channel.setMethodCallHandler(instance);
40+
}
3941
}
4042

4143
FlutterWebviewPlugin(Activity activity, Context context) {

0 commit comments

Comments
 (0)