How to call MethodChannel from an isolate created by android_alarm_manager?


I tried to schedule background service. For that i used It works well.

For my example, I tried to get from my isolate (android_alarm_manager’s callback) the battery level following the flutter tutorial :

If I call manualy my callback it works (so I well do the Android part). If android_alarm_manager call it, I got the following error appear :

Unhandled Exception: MissingPluginException(No implementation found for method getBatteryLevel on channel

It’s weird because, from an other isolate where I used to download file, this plugin used MethodChannel…

Here is my code for android_alarm_manager :

import 'package:flutter/services.dart';

class AndroidManagerCallBack {
  static Future<void> main() async {
    _AndroidManagerCallBack test = _AndroidManagerCallBack();
    await test.getBatteryLevel();

class _AndroidManagerCallBack {
  static const platform = const MethodChannel('');

  Future<void> getBatteryLevel() async {
    String batteryLevel;
    try {
      final int result = await platform.invokeMethod('getBatteryLevel');
      batteryLevel = 'Battery level at $result % .';
    } on PlatformException catch (e) {
      batteryLevel = "Failed to get battery level: '${e.message}'.";

I simply call the callback like :

      Duration(seconds: 20),
      rescheduleOnReboot: true,
      wakeup: false,

In android_alarm_manager’s callback, I can call plugins which used somee MethodChannel but when I tried with my MethodChannel, I got errors…

Someone can guide me 🙂 ?


It seem impossible to call directly MethodChannel through an isolate.

But, with the creation of a plugin i can achieve what i want. So the solution is to create a plugin 🙂 !

Answered By – Eng

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *