简体   繁体   English

在应用程序中的背景中带有插件的位置phonegap cordova for android

[英]Location in Background With Plugin in App phonegap cordova for android

Good community, I am currently using the https://www.npmjs.com/package/cordova-plugin-gpslocation plugin to geolocalize the device when the app is in the foreground and background, when in the background I use the OnPause method and execute A setInterval to execute the method of the plugin to obtain coordinates every X time (GetCurrentPosition). 社区很好,我目前正在使用https://www.npmjs.com/package/cordova-plugin-gpslocation插件在应用程序位于前台和后台时对设备进行地理定位,而在后台使用OnPause方法和执行setInterval以执行插件的方法以每X次获取坐标(GetCurrentPosition)。 MY PROBLEM is that when the screen is turned on it works perfectly and the Location icon appears in the notification bar but when the screen is off it seems to stop working and only recaptures coordinates when I turn on the screen. 我的问题是,当屏幕打开时,它可以正常工作,并且位置图标出现在通知栏中,但是当屏幕关闭时,它似乎停止工作,只能在打开屏幕时重新捕获坐标。

I have the following permissions in the Android Manifest that is in the platform of Android besides that I added the property in the activity tag also in the manifest. 除了在清单中的activity标签中添加了属性之外,我还在Android平台上的Android Manifest中具有以下权限。

<Uses-permission android: name = "android.permission.ACCESS_FINE_LOCATION" />
<Uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" />
<Uses-permission android: name = "android.permission.AUTHENTICATE_ACCOUNTS" />
<Uses-permission android: name = "android.permission.GET_ACCOUNTS" />
<Uses-permission android: name = "android.permission.READ_SYNC_SETTINGS" />
<Uses-permission android: name = "android.permission.WRITE_SYNC_SETTINGS" />
<Uses-permission android: name = "android.permission.RECEIVE_BOOT_COMPLETED" />
<Uses-permission android: name ="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
    <Uses-permission android: name = "android.permission.ACCESS_NETWORK_STATE" />
    <Uses-permission android: name = "android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <Uses-permission android: name = "android.permission.WAKE_LOCK" />
    <Uses-permission android: name = "android.hardware.location" />

 <Activity <span style = "text-decoration: underline;"> android: alwaysRetainTaskState = "true" android: configChanges = "orientation | keyboardHidden | keyboard | screenSize | locale" android: label = "@ string / activity_name "Android: launchMode =" singleTop "android: name =" MainActivity "android: theme =" @ android: style / Theme.DeviceDefault.NoActionBar "android: windowSoftInputMode =" adjustResize ">

If someone can give me a help I would appreciate it or if you need to add some other property in the manifest or something else, Thank you very much. 如果有人可以帮助我,我将不胜感激,或者如果您需要在清单中添加其他属性或其他内容,非常感谢。

It seems that the plugin works only on active state. 看来该插件只能在活动状态下工作。 Only plugins with background tracking works like your expectation .. There are many such plugins , Let me give you the one i am using https://www.npmjs.com/package/cordova-plugin-mauron85-background-geolocation 只有具有后台跟踪功能的插件才能像您期望的那样工作。有很多这样的插件,让我给您一个我正在使用的插件https://www.npmjs.com/package/cordova-plugin-mauron85-background-geolocation

backgroundGeolocation.configure(callbackFn, failureFn, { desiredAccuracy: 10, // for accuracy stationaryRadius: 20, distanceFilter: 30, // minimum distance threshold
interval: 60000 });

This saves a lot of battery and also works on interval and distance basis. 这样可以节省大量电池,并且可以在间隔和距离上工作。 takes sample either only when the device crosses some distance and/or on the specified time.. This will work when the app goes on background .. Thanks and happy coding :) 仅在设备经过一定距离和/或在指定时间时才采样。.当应用程序在后台运行时才可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于在 Android 9 后台运行应用程序的 Cordova 插件 - Cordova plugin for running app in background in Android 9 是他们的任何cordova插件,即使android / ios应用被杀死,该插件也可提供后台服务以获取设备位置 - Is their any cordova plugin which provides background service for getting device location even if android/ios app is killed 在简单的cordova android应用中使用phonegap-facebook-plugin - using phonegap-facebook-plugin in simple cordova android app android 工作室中的 Phonegap/Cordova 插件 - Phonegap/Cordova plugin in android studio Android、Cordova/PhoneGap、Cordova-Plugin-File 上的 SMS/MMS 数据位置 - SMS/MMS data location on Android, Cordova/PhoneGap, Cordova-Plugin-File Cordova / Phonegap:在后台线程中运行FileTransfer插件 - Cordova/Phonegap: run FileTransfer plugin in background thread 当应用程序在Cordova Android应用程序中处于后台时获取用户位置 - Get user location while app is background in cordova android application 为Android部署Phonegap / Cordova应用程序? - Deploying Phonegap / Cordova app for Android? phonegap中的Android后台服务插件 - Android background service plugin in phonegap Phonegap GPS定位插件cordova-plugin-gpslocation - Phonegap GPS location plugin cordova-plugin-gpslocation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM