Skip to content

Instantly share code, notes, and snippets.

@AbhishekDoshi26
Created July 24, 2021 14:30
Show Gist options
  • Save AbhishekDoshi26/d150efac15039684e3865f851ff65533 to your computer and use it in GitHub Desktop.
Save AbhishekDoshi26/d150efac15039684e3865f851ff65533 to your computer and use it in GitHub Desktop.
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "flutter.native/helperChannel";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("helloFromNativeCode")) {
String greetings = helloFromNativeCode();
result.success(greetings);
}
}});
}
private String helloFromNativeCode() {
return "Hello from Native Android Code";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment