question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to start service Intent on calling BackgroundGeolocation.start()

See original GitHub issue

Your Environment

  • Plugin version: 3.0.0-alpha.50
  • Platform: Android
  • OS version: 8.1 (API 27)
  • Device manufacturer and model: Nexus 5X
  • Running in Simulator: Yes
  • Cordova version: 8.1.2
  • Cordova platform version: 7.1.4 (Android)

Context

Using the example code provided, the GPS tracking doesn’t initialize properly and cannot be used.

Expected Behavior

The GPS tracking service should start, and the foreground notification in the top drawer should be visible.

Actual Behavior

Nothing happens, the service isn’t started. Foreground notification does not appear (but the events for background mode triggers in the console.log)

Possible Fix

There has been changes to background mode, and how you start Intents, in Android 8.0+ https://developer.android.com/about/versions/oreo/background

The following issue in the react-native project may be of interest: https://github.com/mauron85/react-native-background-geolocation/issues/172

Debug logs

02-04 09:04:57.034  5194  5270 I com.marianhello.bgloc.BackgroundGeolocationFacade: Initializing plugin
02-04 09:04:57.082  5194  5270 D com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin: Registering event listeners
02-04 09:04:57.109  5194  5270 W PluginManager: THREAD WARNING: exec() call to BackgroundGeolocation.addEventListener blocked the main thread for 27ms. Plugin should use CordovaInterface.getThreadPool().
02-04 09:04:57.117  5194  5230 D NetworkSecurityConfig: No Network Security Config specified, using platform default
02-04 09:04:57.362  5194  5194 D SystemWebChromeClient: file:///android_asset/www/plugins/cordova-plugin-android-softinputmode/www/interface.js: Line 3 : Success
02-04 09:04:57.362  5194  5194 I chromium: [INFO:CONSOLE(3)] "Success", source: file:///android_asset/www/plugins/cordova-plugin-android-softinputmode/www/interface.js (3)
02-04 09:04:57.462  5194  5272 D com.marianhello.bgloc.data.sqlite.SQLiteConfigurationDAO: Configuration persisted with rowId = 1
02-04 09:04:57.466  5194  5272 D com.marianhello.bgloc.BackgroundGeolocationFacade: Service configured with: Config[distanceFilter=50 stationaryRadius=100.0 desiredAccuracy=0 interval=3000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=true stopOnStillActivity=true startOnBoot=false startForeground=true notificationsEnabled=true locationProvider=1 nTitle=PolarFleet GPS tracking nText=enabled nIconLarge= nIconSmall= nIconColor= url=myUrl Threshold=100 httpHeaders={Content-Type=application/json} maxLocations=1 postTemplate={"heading":"@bearing","foo":"bar","lon":"@longitude","id":"ADG198","lat":"@latitude","speed":"@speed","timestamp":""}]
02-04 09:04:57.490  5194  5251 D EGL_emulation: eglMakeCurrent: 0xa9205d80: ver 3 0 (tinfo 0x9563a050)
02-04 09:04:57.508  1638  1941 W ActivityManager: Unable to start service Intent { cmp=myApp/com.marianhello.bgloc.service.LocationServiceImpl (has extras) } U=0: not found

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
int128flycommented, Feb 5, 2019

Thanks for your inputs, I’ve just got it working, apparently the issue was in the @ionic-native/background-geolocation/ngx

Using the following work properly, I will create my own ionic provider at that point.

declare var BackgroundGeolocation: any;

and you were correct we do not have the same issue, sorry for stealing your thread

0reactions
Amsvartnercommented, Feb 5, 2019

I suspect that we may not have the same problem, because everything else works for me (background/foreground mode, app settings etc) but nothing happens when I call start() in the checkStatus callback, and no notification about background mode is shown in the drawer at the top.

Javascript

BackgroundGeolocation.configure({
    locationProvider : BackgroundGeolocation.ACTIVITY_PROVIDER,
    desiredAccuracy : BackgroundGeolocation.HIGH_ACCURACY,
    stationaryRadius : 100,
    distanceFilter : 50,

    startForeground : true,
    notificationTitle : 'GPS tracking',
    notificationText : 'enabled',

    debug : true,
    interval : 3000,
    fastestInterval : 5000,
    activitiesInterval : 10000,
    maxLocations : 1,
    url : "http://something",

    httpHeaders : {
        'Content-Type' : 'application/json'
    }
});

BackgroundGeolocation.on('location', function (location) {
    console.log(location);
                    
    BackgroundGeolocation.startTask(function (taskKey) {
         BackgroundGeolocation.endTask(taskKey);
    });
});

BackgroundGeolocation.on('stationary', function (stationaryLocation) {
    console.log(stationaryLocation);
});

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');
});

BackgroundGeolocation.on('stop', function () {
    console.log('[INFO] BackgroundGeolocation service has been stopped');
});

BackgroundGeolocation.on('authorization', function (status) {
    console.log('[INFO] BackgroundGeolocation authorization status: ' + status);
    
    if (status !== BackgroundGeolocation.AUTHORIZED) {
        setTimeout(function () {
            var showSettings = confirm('App requires location tracking permission. Would you like to open app settings?');
    
            if (showSettings) {
                return BackgroundGeolocation.showAppSettings();
            }
        }, 1000);
    }
});

BackgroundGeolocation.on('background', function () {
    console.log('[INFO] App is in background');
    BackgroundGeolocation.configure({ debug : true });
});

BackgroundGeolocation.on('foreground', function () {
    console.log('[INFO] App is in foreground');
    BackgroundGeolocation.configure({ debug : false });
});

BackgroundGeolocation.on('abort_requested', function () {
    console.log('[INFO] Server responded with 285 Updates Not Required');
});

BackgroundGeolocation.on('http_authorization', function () {
    console.log('[INFO] App needs to authorize the http requests');
});

BackgroundGeolocation.checkStatus(function (status) {
    console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
    console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
    console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization);

    if (!status.isRunning) {
        BackgroundGeolocation.start(); //nothing happens..
    }
});

console.log output

[INFO] BackgroundGeolocation service is running false
[INFO] BackgroundGeolocation services enabled true
[INFO] BackgroundGeolocation auth status: 1
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to start service Intent on calling ... - GitHub
Unable to start service Intent on calling ... BackgroundGeolocation.start(); is showing not throwing any error but location is not getting ...
Read more >
Android 8.0: java.lang.IllegalStateException: Not allowed to ...
After targeting API level 26, my application fails to start service on Android 8.0 on background. Caused by: java.lang.IllegalStateException: ...
Read more >
cordova-plugin-saralweb-background-geolocation - npm package ...
cordova-plugin-saralweb-background-geolocation. Description. Cross-platform background location tracking plugin for Cordova / PhoneGap with battery-saving ...
Read more >
Cordova Background Geolocation Tracking - Ionic Framework
start (); // If you wish to turn OFF background-tracking, call the #stop method ...
Read more >
Access location in the background - Android Developers
When you remove this permission, all-the-time access to location isn't an option for the app on devices that run Android 10. Make sure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found