Yukams / background_locator_fixed

A Flutter plugin for updating location in background.
MIT License
50 stars 94 forks source link

Foreground Service location (Android 14) crash #131

Open shashikiran918 opened 3 weeks ago

shashikiran918 commented 3 weeks ago

Fatal Exception: java.lang.RuntimeException Unable to create service yukams.app.background_locator_2.IsolateHolderService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{87dfcc9 20206:com.icore.cproll/u0a738} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission.

AndroidManifest.xml

`<manifest` xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxxx">
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" `/>`
    <uses-permission `android:name="android.permission.WAKE_LOCK"/>`
    <uses-permission android:name="android.permission.VIBRATE" `/>`
    <uses-permission `android:name="android.permission.INTERNET"/>`
    <uses-permission `android:name="android.permission.FOREGROUND_SERVICE"/>`
    <uses-permission `android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>`
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" `/>`
    <uses-permission `android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>`
    <uses-permission `android:name="android.permission.POST_NOTIFICATIONS"/>`
    <uses-permission `android:name="android.permission.SCHEDULE_EXACT_ALARM"/>`
    <application
        android:name="${applicationName}"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="xxxxx">
        <activity
            android:name=".MainActivity"
         android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:showWhenLocked="true"
            android:turnScreenOn="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" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="yukams.app.background_locator_2.IsolateHolderService"
            android:permission="android.permission.FOREGROUND_SERVICE"
            android:exported="true"
            android:foregroundServiceType = "location"/>
        <receiver android:name="yukams.app.background_locator_2.BootBroadcastReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
        <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />
        <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
        <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
            </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>

build.gradle


   defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.xxx.xxx"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
GerlanStanley commented 2 weeks ago

It's happening to me even with all the permissions added