在Flutter中实施alarm_manager时出错。 遵循alarm_manager插件的自述文件,但它给我一个错误 错误PlatformException(错误,AlarmManager错误: 未设置PluginRegistrantCallback。你忘了打电话吗 AlarmService.setPluginRegistrant?有关说明,请参见自述文件 空)
Androidmanifest.xml file;
<code>
<application
tools:replace="android:label"
android:name="io.flutter.app.FlutterApplication"
android:label="xx"
android:icon="@mipmap/ic_launcher">
...
</application>
Application.java;
package com.app.demoapp;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.androidalarmmanager.AlarmService;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
AlarmService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Mainactivity.java;
package com.app.demoapp;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
答案 0 :(得分:0)
有时热重载和热重启不会注册新添加的插件。尝试停止并运行。如果不起作用,请运行flutter clean
然后再次运行