Cordova-plugin-background-geolocation: Plugin not starting or .on('start') does not hit any way

Created on 18 Sep 2019  Â·  14Comments  Â·  Source: mauron85/cordova-plugin-background-geolocation

Your Environment

  • Plugin version: 3.0.6
  • Platform: Android
  • OS version: 9.0.0
  • Device manufacturer and model: Oneplus 6

  • Running in Simulator: NO

  • Cordova version (cordova -v): 9.0.0
  • Cordova platform version (cordova platform ls): android 8.0.0
  • Plugin configuration options:

    ```
    BackgroundGeolocation.configure({
    locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER, //DISTANCE_FILTER_PROVIDER //ACTIVITY_PROVIDER
    desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
    stationaryRadius: 5,
    distanceFilter: 5,
    notificationTitle: 'Background tracking',
    notificationText: 'enabled',
    debug: true,
    interval: 10000, // 10 seconds => The minimum time interval between location updates in milliseconds. @see Android docs for more information.
    fastestInterval: 5000, // 5 seconds => Fastest rate in milliseconds at which your app can handle location updates. @see Android docs.
    activitiesInterval: 10000, // 10 seconds => Rate in milliseconds at which activity recognition occurs. Larger values will result in fewer activity detections while improving battery life.
    stopOnTerminate: false,
    notificationsEnabled: true,
    startForeground: true,
    url: ''
    });

* Link to your project:

## Context
<!--- Provide a more detailed introduction to the issue itself, and why you consider it to be a bug -->

## Expected Behavior
Should hit this method:
 ```
        BackgroundGeolocation.on('start', function () {
            console.log('[INFO] BackgroundGeolocation service has been started');
        });

Actual Behavior

Nothing happening, not even the foreground notification showing up. No JS error logs on console what so ever

Possible Fix

Steps to Reproduce


  1. Copy paste the example on the plugin read me page (exactly)
  2. It starts the background location service using:
            if (!status.isRunning) {
                BackgroundGeolocation.start(); //triggers start on start event
            }
  1. These methods don't get hit at all

        BackgroundGeolocation.on('location', function (location) {
    
            console.log("Got location: " + JSON.stringify(location));
            alert("Got location: " + JSON.stringify(location));
    
            // handle your locations here
            // to perform long running operation on iOS
            // you need to create background task
            BackgroundGeolocation.startTask(function (taskKey) {
                // execute long running task
                // eg. ajax post location
                // IMPORTANT: task has to be ended by endTask
                BackgroundGeolocation.endTask(taskKey);
            });
        });
    
        BackgroundGeolocation.on('error', function (error) {
            console.log('[ERROR] BackgroundGeolocation error:', error.code, error.message);
        });
    
        BackgroundGeolocation.on('start', function () {
            console.log('[INFO] BackgroundGeolocation service has been started');
        });
    

Context

Debug logs

stale

All 14 comments

Any thoughts on this ? @mauron85

I have the same problem with Android 9+devices. @biswas123 did you find any solution?

IMPORTANT!!

Hi all,

I just found that if you have some tags like <edit-config> or <config-file> on your project's config.xml file, then the plugin fails to start the geolocation i.e BackgroundGeolocation.start() never hits!!!!!!

How to fix this ? @mauron85
Think the AndroidManifest.xml file is not being properly updated.

To reproduce just add a tag on your config.xml file like, my project has the following lines:

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:allowBackup="false" />
            <application android:fullBackupContent="false" />
</edit-config>

Then run your project. I tried this on a sample hello world project.


Then remove the lines and test again, after removing these lines the plugin works normally.

IMPORTANT!!

Hi all,

I just found that if you have some tags like <edit-config> or <config-file> on your project's config.xml file, then the plugin fails to start the geolocation i.e BackgroundGeolocation.start() never hits!!!!!!

How to fix this ? @mauron85
Think the AndroidManifest.xml file is not being properly updated.

To reproduce just add a tag on your config.xml file like, my project has the following lines:

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:allowBackup="false" />
            <application android:fullBackupContent="false" />
</edit-config>

Then run your project. I tried this on a sample hello world project.

Then remove the lines and test again, after removing these lines the plugin works normally.

In my case something similar happened to me with this plugins, when it seemed that everything is almost complete, from one moment to another, some options stopped working, that is, it presented a fairly high instability.

Since the last update of the plugin (3.1.0), what I did was create the project from scratch, install the plugins and migrate everything.

By doing this, the plugin worked like a charm, options like "stopOnTerminate" worked very well for me.

I hope I contributed to the solution

@anRoswell this looks like a cordova issue to me.

@anRoswell this looks like a cordova issue to me.

Adding or tags on your project's config.xml file leads to generating AndroidManifest.xml file improperly or incomplete.

Thank you so much @biswas123! That's was the problem, I have two edit-config sentences. I'm looking for an alternative as they're necessary for my project.

Is there any official solution to this problem? I have the same config as @anRoswell

Ok, I made a hook to add to AndroidManifest.xml the settings I need manually and deleted the _edit-config_ sentences from _config.xml_

hi @Genarito

Can you share the how you used the hook?

This would be a temporary fix, but how do we keep up with this?
@mauron85
On Sat, Oct 19, 2019, 05:31 Genarito notifications@github.com wrote:

Ok, I made a hook to add to AndroidManifest.xml the settings I need
manually and deleted the edit-config sentences from config.xml

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mauron85/cordova-plugin-background-geolocation/issues/629?email_source=notifications&email_token=ACFQD4G5QVOJ52JM33VE2TLQPJDFBA5CNFSM4IX5NG3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBWPEHQ#issuecomment-544010782,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACFQD4BIBFR4WYVIB6C4SYTQPJDFBANCNFSM4IX5NG3A
.

Sure! I made a file called add_manifest_config.sh in a folder called scripts with this code:

#!/bin/bash


MANIFEST=./platforms/android/app/src/main/AndroidManifest.xml
[[ -e $MANIFEST ]] || { echo "Manifest not found at $MANIFEST." ; exit 1; }

grep -q android:allowBackup $MANIFEST && { echo "It has been modified, nothing to do."; exit 0; }


REPLACEMENT='<application'


ADDITION='android:allowBackup="false" android:fullBackupContent="false"';

sed -i -e "s/${REPLACEMENT}/${REPLACEMENT} ${ADDITION}/" $MANIFEST

In my case I needed to modify allowBackup and fullBackupContent settings.

Finally I set the execution permission:

chmod +x add_manifest_config.sh

And set the hook in config.xml:

<platform name="android">
        ...
        <hook src="scripts/add_manifest_config.sh" type="after_platform_add" />
        ...
</platform>

I know it's not perfect but it worked for me. It helps :D

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

IMPORTANT!!

Hi all,

I just found that if you have some tags like <edit-config> or <config-file> on your project's config.xml file, then the plugin fails to start the geolocation i.e BackgroundGeolocation.start() never hits!!!!!!

How to fix this ? @mauron85
Think the AndroidManifest.xml file is not being properly updated.

To reproduce just add a tag on your config.xml file like, my project has the following lines:

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:allowBackup="false" />
            <application android:fullBackupContent="false" />
</edit-config>

Then run your project. I tried this on a sample hello world project.

Then remove the lines and test again, after removing these lines the plugin works normally.

Hi thank you. I had the same issue. And it was resolved by removing the "edit-config" from config.xml

I wonder why it is this way. I was evolving the plugin to check if it fits my needs. By now there are two issues which need hacks to solve them

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed, because it has not had recent activity. If you believe this issue shouldn't be closed, please reopen or write down a comment requesting issue reopening with explanation why you think it's important. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frankzhangxd picture frankzhangxd  Â·  6Comments

kleeb picture kleeb  Â·  8Comments

ThorvaldAagaard picture ThorvaldAagaard  Â·  9Comments

mahmed-ntd picture mahmed-ntd  Â·  10Comments

maurojones picture maurojones  Â·  3Comments