npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@triplesense/capacitor-background-location

v1.2.0-0

Published

Bg Location Feature

Downloads

2

Readme

Capacitor Background Location Plugin

Capacitor plugin for background location tracking

Current version 0.0.1

See our detailed changelog for the latest features, improvements and bug fixes.

Installation

npm

npm install @triplesense/capacitor-background-location
npx cap sync

Usage example

import { BgLocation } from '@triplesense/capacitor-background-location';

@Component({
  selector: 'home-page',
  templateUrl: 'home.page.html',
})
export class HomePage {
  /**
   *
   */
  onStartClick = async (): Promise<void> => {
    return BgLocation.start()
      .then(() => {
        console.log(`👍 [BackgroundGeolocation] started `);
      })
      .catch(error => {
        console.error(`❌ [BackgroundGeolocation] not started `, error);

        if (error?.message === 'PERMISSION_DENIED_ERROR') {
          this.onPermissionDenied();
        }
      });
  };

  /**
   *
   */
  onStopClick = (): Promise<void> => {
    const onComplete = () => {
      console.log(`[BackgroundGeolocation] stopped`);
    };

    const onError = () => {
      console.error(`[BackgroundGeolocation] not stopped`);
    };

    return BgLocation.stop().then(onComplete).catch(onError);
  };

  /**
   *
   */
  enableActivities = (): Promise<void> => {
    return BgLocation.enableActivities()
      .then(() => {
        console.log(`👍 [BackgroundGeolocation] activities enabled `);
      })
      .catch(error => {
        console.error(
          `❌ [BackgroundGeolocation] activities not enabled `,
          error,
        );
      });
  };

  /**
   *
   */
  disableActivities = (): Promise<void> => {
    return BgLocation.disableActivities()
      .then(() => {
        console.log(`👍 [BackgroundGeolocation] activities disabled `);
      })
      .catch(error => {
        console.error(
          `❌ [BackgroundGeolocation] activities not disabled `,
          error,
        );
      });
  };

  /**
   *
   */
  hasBackgroundLocationPermission = () => {
    return this.locationSettings.isBackgroundLocationGranted();
  };

  /**
   *
   */
  isEnabled = async (): Promise<boolean> => {
    return (await BgLocation.isRequestingLocations()).result;
  };
}

Android

Variables

This plugin will use the following project variables (defined in your app's variables.gradle file):

  • $playServicesLocationVersion: version of com.google.android.gms:play-services-location (default: 17.1.0)
  • $firebaseMessagingVersion: version of com.google.firebase:firebase-messaging (default: 21.0.1)
  • $workVersion: version of androidx.work:work-runtime (default: 2.4.0)

Permissions

Add the following permissions to the application's AndroidManifest.xml:

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

  <!-- Required only when requesting background location access on
      Android 10 (API level 29) and higher. -->
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />


   <!-- Required for Android 9 (API level 28) and below. -->
  <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
  <!-- Required for Android 10+ (API level 29+)-->
  <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>

The permissions above are for access device location and activity recognition.

Read about Setting Permissions in the Android Guide for more information on setting Android permissions.

How permissions work

Android 9 and bellow

TODO

Android 10

TODO

Android 11 and above

TODO

Notification Color

You can customize notification's colors by editing res/values.colors.xml on you app project:

<resources>
  <color name="notificationColor">#02de82</color>
</resources>

Notification's localization

You can localize notification's messages by editing res/values.strings.xml on you app project:

<resources>
    <plurals name="num_locations_reported">
        <item quantity="zero">No location reported</item>
        <item quantity="one">One location reported</item>
        <item quantity="other">%d locations reported</item>
    </plurals>
</resources>

iOS

TODO

API

start()

start() => Promise<void>

Starts tracking location

platforms: android, ios

Since: 1.0.0


stop()

stop() => Promise<void>

Stops tracking location

platforms: android, ios

Since: 1.0.0


hasPermissionGranted()

hasPermissionGranted() => Promise<{ result: boolean; }>

Check if required location permissions are granted

platforms: android, ios

Returns: Promise<{ result: boolean; }>

Since: 1.0.0


enableActivities()

enableActivities() => Promise<void>

Starts tracking activities

platforms: android, ios

Since: 1.0.0


disableActivities()

disableActivities() => Promise<void>

Stops tracking activities

platforms: android, ios

Since: 1.0.0


isRequestingLocations()

isRequestingLocations() => Promise<{ result: boolean; }>

Check if tracking is enabled (locations are being emitted)

platforms: android, ios

Returns: Promise<{ result: boolean; }>

Since: 1.0.0


addListener(string, ...)

addListener(eventName: string, listenerFunc: ListenerCallback) => Promise<PluginListenerHandle> & PluginListenerHandle

platforms: android, ios

| Param | Type | | ------------------ | ------------------------------------------------------------- | | eventName | string | | listenerFunc | ListenerCallback |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


Interfaces

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

Type Aliases

ListenerCallback

(err: any, ...args: any[]): void