Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70434

crash app on android 8.1.0 when background geolocation is started. I used "cordova-plugin-mauron85-background-geolocation": "^2.3.6", and "@ionic-native/background-geolocation": "5.0.0-beta.21". Then, My code is

$
0
0

@winlhanphyo1 wrote:

import {
BackgroundGeolocation,
BackgroundGeolocationConfig,
BackgroundGeolocationResponse
} from ‘@ionic-native/background-geolocation/ngx’;
import { LocalNotifications } from ‘@ionic-native/local-notifications/ngx’;
import { PowerManagement } from ‘@ionic-native/power-management/ngx’;
import {
BackgroundMode,
BackgroundModeConfiguration } from ‘@ionic-native/background-mode/ngx’;

watchCurrent() {
console.log(‘LiveMapService: watchUserCurrentPosition’);
// only background.
this.backgroundMode.enable();
this.backgroundMode.setDefaults(this.backgroundModeSetting);

    this.powerManagement.dim().then(() => {
        console.log('Wakelock acquired');
    });

    this.powerManagement.setReleaseOnPause(false).then(() => {
        console.log('setReleaseOnPause successfully');
    });

    // app is running in background.
    this.backgroundMode.on('activate').subscribe(() => {
        this.backgroundGeolocation.start();
        this.backgroundMode.disableWebViewOptimizations();
    });

    // app is running on foreground.
    this.backgroundMode.on('deactivate').subscribe(() => {
        this.backgroundGeolocation.stop();
    });

    // only foreground;
    this.geolocation.watchPosition(this.geoConfig)
        .pipe(
            takeUntil(this.liveEnd$),
            filter((position: Geoposition) => {
                return !!(position as Geoposition).coords;
            })
        )
        .subscribe(
            (position: Geoposition) => {
                this.zone.run(() => {
                    const location = position.coords;
                    this.currentGeoPointSubject.next({
                        lat: location.latitude,
                        lng: location.longitude,
                        timestamp: Date.now()
                    });

                    this.localNotifications.schedule({
                        text: 'Foreground Latitude ' + location.latitude + ' Longitude ' + location.longitude,
                        trigger: { at: new Date(new Date().getTime() + 5) },
                        led: 'FF0000',
                        sound: null
                    });

                    this.debugService.push([
                        `LiveMapService: watchUserCurrentPosition:`,
                        `lat: ${location.latitude}`,
                        `lng: ${location.longitude}`,
                        // `timestamp: ${Date.now()}`
                    ]);
                });
            },
            err => {
                console.error(err);
                this.debugService.push([
                    `LiveMapService: watchUserCurrentPosition: thrown Error.`,
                    `${err.message}`
                ]);
            }
        );
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>