我的警报管理器扑朔迷离,无法在正确的时间触发。有时要迟到5分钟,有时我得把手机唤醒后才能启动。 我怎样才能使警报更加准确,并能无故障地开火。我正在使用它来获取行驶中的汽车的位置,而5分钟的故障窗口是很长的时间。
下面是我的代码。
Future<void> _locateDriver() async {
await AndroidAlarmManager.initialize();
await AndroidAlarmManager.periodic(const Duration(minutes: 1), helloAlarmID,
printLocation, wakeup: true, exact: true, rescheduleOnReboot:true).then((val) => print(val));
------
}
我的android清单看起来像这样。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:name=".Application"
android:label="xxxxxx"
android:icon="@mipmap/ic_launcher"
tools:ignore="GoogleAppIndexingWarning">
<service
android:name="io.flutter.plugins.androidalarmmanager.AlarmService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"/>
<receiver
android:name="io.flutter.plugins.androidalarmmanager.AlarmBroadcastReceiver"
android:exported="false"/>
<receiver
android:name="io.flutter.plugins.androidalarmmanager.RebootBroadcastReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
我将位置打印到mqtt的位置在这里。
static void printLocation() async{
Isolate.current.hashCode;
print(await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high));
mqttSendCoordinates(await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high));
new Future.delayed(const Duration(seconds: 20), () async {
print(await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high));
mqttSendCoordinates(await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high));
});
new Future.delayed(const Duration(seconds: 40), () async {
print(await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high));
mqttSendCoordinates(await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high));
});
}