CHANNEL

setMethodCallHandler

call

result

>

// This method is invoked on the main thread.

// TODO

);

Add the Android Java code that uses the Android battery APIs to
retrieve the battery level. This code is exactly the same as you
would write in a native Android app.

First, add the needed imports at the top of the file:

import

android.content.ContextWrapper

import

android.content.Intent

import

android.content.IntentFilter

import

android.os.BatteryManager

import

android.os.Build.VERSION

import

android.os.Build.VERSION_CODES

import

android.os.Bundle