capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
177 stars 54 forks source link

Getting Error: Service not running. #72

Closed ChandruBee closed 1 year ago

ChandruBee commented 1 year ago

Describe the bug Getting message: "Service not running." in result of BackgroundGeolocation.addWatcher

To Reproduce Steps to reproduce the behavior:

  1. Install package
  2. Follow the documentation
  3. Add permissions
  4. Run Project
  5. And Getting Error

Expected behavior Set Add watcher and show details in notification window

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

diachedelic commented 1 year ago

Please let me know if you resolve this issue. I do not have a Vivo phone to test on.

ChandruBee commented 1 year ago

sorry for late reply , this is my mistake which i miss something in manifest and now it is working like charm, thanks

Aksoom-Hussain commented 1 year ago

facing same issue

here is my manifest.xml file always getting 'Service not running' using the code snippet use in readme.md

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.shaheen.provider">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="com.shaheen.provider.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher" />
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyAoXA-p3pF5G3xVIMo2OXHviHZLFFMjoEc"/>

    </application>

    <!-- Permissions -->
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

</manifest>
gregor-srdic commented 1 year ago

I am also encountering this error. Can you please share your working manifest?

diachedelic commented 1 year ago

Please try using v1.2.4 and see if that fixes the problem.

gregor-srdic commented 1 year ago

The problem was I didn't declare a service within the activity in the manifest. It looks like this is missing in Android configuration section in readme?

<service android:name="com.equimaps.capacitor_background_geolocation.BackgroundGeolocationService" android:enabled="true" android:exported="true" android:foregroundServiceType="location" />
chandruBalamurugan1995 commented 1 year ago

yes it is, I Used the documentation of version 0.3 to resolve the issue. https://github.com/capacitor-community/background-geolocation/tree/0.3.x

and my manifest look like

`<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.ionic.starter">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
  <service
    android:name="com.equimaps.capacitor_background_geolocation.BackgroundGeolocationService"
    android:enabled="true"
    android:exported="true"
    android:foregroundServiceType="location" />

    <activity
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
        android:name="io.ionic.starter.MainActivity"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBarLaunch"
        android:launchMode="singleTask"
        android:exported="true">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"></meta-data>
    </provider>
</application>

<!-- Permissions -->

<uses-permission android:name="android.permission.INTERNET" />

`

diachedelic commented 1 year ago

That section of the README was removed. v1.2.4 does not require you to configure your AndroidManifest.xml. Please let me know if using v1.2.4 does not solve this issue.