Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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()
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment