问题描述
我们正忙于开发具有以下要求的应用程序,
为此,我们正在尝试使用Background Location和Background Fetch函数。 我们创建了一个概念验证应用,该应用可以执行以下操作,
后台监听器的设置
LocationManager locMan = LocationManager.getLocationManager();
if (locMan == null) {
Dialog.show("Location Error","Location Manager not found","OK",null);
} else {
if (!locMan.isGPSDetectionSupported()) {
Dialog.show("Location Error","GPS detection not supported.",null);
} else {
if (!locMan.isGPSEnabled()) {
Dialog.show("Location Error","GPS not enabled. Please close the app,turn on your location and try again.",null);
} else {
if (locMan.isBackgroundLocationSupported()) {
locMan.setBackgroundLocationListener(LocationListener.class);
Dialog.show("Location","Background location listener loaded.",null);
} else {
Dialog.show("Location Error","Background location not supported",null);
}
}
}
}
还有监听器类本身,
public class LocationListener implements com.codename1.location.LocationListener {
@Override
public void locationUpdated(Location arg0) {
String msg = arg0.getLatitude() + " - " + arg0.getLongitude();
ASDTester.logMsg(ASDTester.MSG_LOC_COORDS,msg);
}
@Override
public void providerStateChanged(int arg0) {
String msg = "" + arg0;
ASDTester.logMsg(ASDTester.MSG_LOC_STATE_CHANGED,msg);
}
}
对ASDTester.logMsg(int type,String msg)的调用仅在sqlite数据库表中创建一条记录
设置背景提取间隔,
if (display.getInstance().isBackgroundFetchSupported()) {
display.getInstance().setPreferredBackgroundFetchInterval(60);
Dialog.show("Background","Background Fetch Interval set",null);
} else {
Dialog.show("Background Error","Background Fetch Not Supported",null);
}
实施performBackgroundFetch
@Override
public void performBackgroundFetch(long arg0,Callback<Boolean> arg1) {
logMsg(MSG_BGF_TIMESTAMP,System.currentTimeMillis() + "");
arg1.onSucess(Boolean.TRUE);
}
最后是iOS的构建提示
ios.background_modes=fetch,location
该实现不适用于Android或iOS。 位置侦听器在初始化时仅触发一次。 而且后台抓取根本不会触发。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)