A Flutter plugin for registering Dart callbacks when the Android device boots up.
Platform | Supported |
---|---|
Android | ✔️ Yes |
iOS | ❌ No |
Web | ❌ No |
Windows | ❌ No |
Linux | ❌ No |
MacOS | ❌ No |
flutter pub add flutter_boot_receiver
In your AndroidManifest.xml
:
android:installLocation="internalOnly"
in your manifest
tag. Only devices installed in internal storage can receive the BOOT_COMPLETE
broadcast in Android.<manifest
android:installLocation="internalOnly"
>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
application
tag:<service
android:name="com.flux.flutter_boot_receiver.BootHandlerService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
/>
<receiver
android:enabled="true"
android:exported="true"
android:name="com.flux.flutter_boot_receiver.BootBroadcastReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Your AndroidManifest.xml
should now have a structure similar to this:
<manifest
android:installLocation="internalOnly"
>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- Other permissions... -->
<application>
<!-- Other activities, services etc... -->
<service
android:name="com.flux.flutter_boot_receiver.BootHandlerService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
/>
<receiver
android:enabled="true"
android:exported="true"
android:name="com.flux.flutter_boot_receiver.BootBroadcastReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
import 'package:flutter_boot_receiver/flutter_boot_receiver.dart';
@pragma('vm:entry-point')
void callback() async {
// Code here will be executed when the device boots up
}
await BootReceiver.initialize(callback);