Guest User

Untitled

a guest
Dec 12th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //On Android
  2. class MainActivity() : FlutterActivity() {
  3.  
  4. override fun onCreate(savedInstanceState: Bundle?) {
  5. super.onCreate(savedInstanceState)
  6.  
  7. GeneratedPluginRegistrant.registerWith(this)
  8. MethodChannel(flutterView, "samples.flutter.io/battery").setMethodCallHandler { call, result ->
  9. if (call.method == "getBatteryLevel") {
  10. val batteryLevel = getBatteryLevel()
  11.  
  12. if (batteryLevel != -1) {
  13. result.success(batteryLevel)
  14. } else {
  15. result.error("UNAVAILABLE", "Battery level not available.", null)
  16. }
  17. } else {
  18. result.notImplemented()
  19. }
  20. }
  21. }
  22. }
Add Comment
Please, Sign In to add comment