Code Monkey home page Code Monkey logo

cordova-plugin-bgs's Introduction

BackgroundGeolocationService with notification for Android

Simple cordova plugin for capture geodata in background mode, send to server and notify (if needed) user with local notification. Plugin use awesome Cordova Local Notification Plugin builder it is making available to you all its API.

Example usage

var config = {
    serverUrl: 'https://example.com?my_param1=123&my_param2=321',
    startOnBoot: true,  // Load service on boot
    // Android LocationListener params, see [this](https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper)) article
    minDistance: 10,
    minTime: 24 * 60 * 60 * 1000,
    minAccuracity: 150,
    distanceFilter: 100,
    throttle: 1 * 60 * 1000,  // Throttle http requests, ms
    // Default Notification property
    defaults: {smallIcon: 'res://icon'},
    defaultRequestParams: {access_key: 'ADSsad2129casjas8'} // default post params
};
window.bgs.configure(config, function() {
    window.bgs.start(
        function() { console.log('bgs init successful'); },
        function() { console.log('bgs init failure'); }
    );
});

Example server request

POST https://example.com?my_param1=123&my_param2=321
BODY latitude=33&longitude=34&accuracy=100&access_key=ADSsad2129casjas8

Example server response

You must response json data on request. Response json format similiar to Cordova Local Notification Plugin schedule function api. See more info there. If you not want to show notification response to client with http code 204.

for on notification

{"text": "Hello World"}

or for multiplie notification

[{"text": "Hello One"}, {"text": "Hello Two"}]

Capture event in cordova code

You may pass additional data and capture click event in client JavaScript code. See more info there.

{"text": "My Custom Notification", "data": {"myDataId": 123}}

cordova.plugins.notification.local.on('click', function(notification) {
    if (notification.data) {
        if (typeof notification.data === 'string') {
            // BUG: https://github.com/katzer/cordova-plugin-local-notifications/issues/538
            notification.data = JSON.parse(notification.data);
        }
        if (notification.data.myDataId) {
            alert('Capture click with myDataId: ' + myDataId);
        }
    }
});

Api Overview

window.bgs.*

start():

start BackgroundGeolocation service

stop():

stop BackgroundGeolocation service

restart():

stop BackgroundGeolocation service

configure(config):

configure BackgroundGeolocation service

Note: you must restart bgs after configure

config = {
    serverUrl: 'https://example.com?my_param1=123&my_param2=321',
    startOnBoot: true,  // Load service on boot
    // Android LocationListener params, see [this](https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper)) article
    minDistance: 10,
    minTime: 24 * 60 * 60 * 1000,
    throttle: 1 * 60 * 1000,  // Throttle http requests, ms
    // Default Notification property
    defaults: {smallIcon: 'res://icon', sound: 'file://sound.mp3'}
}

Note

In IOS you may wake up app and process response in JavaScript code.

You may use this plugin with Cordova BackgroundGeoLocation Plugin for setup similiar behavior on IOS. Just remove src/android from BackgroundGeoLocation plugin directory.

cordova-plugin-bgs's People

Contributors

hgenru avatar greensea avatar

Stargazers

 avatar Roberto Robson avatar

Watchers

James Cloos avatar  avatar

Forkers

greensea

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.