background_locator
background_locator copied to clipboard
Restart service on device reboot (Android only)
`1.Add the boot receive permission to AndroidManifest.xml:
<receiver android:name="rekab.app.background_locator.BootBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
... ... ... `
The above said code is not working after i reboot the device. It has no effect.
Hi @Puspharaj Thank you for opening an issue, and sorry for answering late, I'll investigate the problem.
The same problem
The same problem After reboot, the application crashes.
FATAL EXCEPTION: main
Process: driver.mobile.collectero, PID: 2962
java.lang.RuntimeException: Unable to start receiver rekab.app.background_locator.BootBroadcastReceiver: kotlin.TypeCastException: null cannot be cast to non-null type kotlin.String
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3018)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1544)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: kotlin.TypeCastException: null cannot be cast to non-null type kotlin.String
at rekab.app.background_locator.BackgroundLocatorPlugin$Companion.startIsolateService(BackgroundLocatorPlugin.kt:72)
at rekab.app.background_locator.BackgroundLocatorPlugin$Companion.registerAfterBoot(BackgroundLocatorPlugin.kt:189)
at rekab.app.background_locator.BootBroadcastReceiver.onReceive(BootBroadcastReceiver.kt:11)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3011)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1544)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.0, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio
[✓] Connected device (3 available)
• No issues found!
Application property
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
background_locator: ^1.6.0+1-beta
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="driver.mobile.collectero">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:label="collectero"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="YOUR KEY HERE"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- background location service-->
<service android:name="rekab.app.background_locator.IsolateHolderService"
android:permission="android.permission.FOREGROUND_SERVICE"
android:exported="true"
android:foregroundServiceType = "location"/>
<receiver android:name="rekab.app.background_locator.BootBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "driver.mobile.collectero"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Same 😫
@resfandiari I tried applying your fix (#297) but it still didn't work (tested on Google Pixel 4a with Android 12). I still get an error message that the app crashed after reboot, and the background service never seems to start. Anything more than this commit needed for a complete fix?
@resfandiari I tried applying your fix (#297) but it still didn't work (tested on Google Pixel 4a with Android 12). I still get an error message that the app crashed after reboot, and the background service never seems to start. Anything more than this commit needed for a complete fix?
There is a second problem #263 even though I fixed this one And this PR https://github.com/rekabhq/background_locator/pull/292 fixed a second problem. Please wait until these PRs #292 #297 are merged into master.
Are there any news on this topic? Thank you!
@resfandiari still got crashes on phone reboot ?
@resfandiari still got crashes on phone reboot ?
yes because this PR #292 has not yet been merged.
@resfandiari I made a working fork of this repo. Any idea where I could share it so everyone could try it and see if they can work with it ? It's just a compilation of the currently opened pull request but it took me a while so if I could save some time to someone else...
Still crashes are occur Any Updates
Still crashes are occur Any Updates
use this https://pub.dev/packages/background_locator_2
@resfandiari It only works on an emulator but does not work on real devices...
@resfandiari It only works on an emulator but does not work on real devices...
That's not true. It works perfectly, I tested it on real device. I think your setup has problem https://github.com/Yukams/background_locator_fixed/wiki/Setup