Skip to content

Instantly share code, notes, and snippets.

@florent37
Created December 12, 2018 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florent37/8c9e99f4387e297e239d3b5bc2094a36 to your computer and use it in GitHub Desktop.
Save florent37/8c9e99f4387e297e239d3b5bc2094a36 to your computer and use it in GitHub Desktop.
//On Android
class MainActivity() : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
MethodChannel(flutterView, "samples.flutter.io/battery").setMethodCallHandler { call, result ->
if (call.method == "getBatteryLevel") {
val batteryLevel = getBatteryLevel()
if (batteryLevel != -1) {
result.success(batteryLevel)
} else {
result.error("UNAVAILABLE", "Battery level not available.", null)
}
} else {
result.notImplemented()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment