【发布时间】:2016-04-21 18:15:45
【问题描述】:
我正在尝试对我的代号一个应用程序实施地理围栏。我按照 github 上的示例执行所有操作,但我的进入和退出方法似乎没有触发。我在构建提示中包含了 GPlayServices 以及 android.playService.* 和 ios.locationUsageDescription。
我已尝试使用 ios 和 android 设备对其进行测试。
下面是我的代码
在 onStart() 方法中
public void start() {
if(current != null){
current.show();
return;
}
u = new UIBuilder();
Display.getInstance().lockOrientation(true);
Location loc = new Location();
loc.setLatitude(-26.15739);
loc.setLongitude(28.127099999999928);
Geofence gf = new Geofence("test", loc, 1000, 100000);
LocationManager.getLocationManager().addGeoFencing(GeofenceListenerImpl.class, gf);
if (Preferences.get("userId", "error").equals("error")) {
setUpLoginForm();
} else {
setUpMainPage();
}
}
实现
public class GeofenceListenerImpl implements GeofenceListener {
public GeofenceListenerImpl() {
}
public void onExit(String id) {
if(Display.getInstance().isMinimized()) {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage1");
ln.setAlertTitle("Welcome");
ln.setAlertBody("Thanks for arriving! isminimized");
Display.getInstance().scheduleLocalNotification(ln, System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE);
} else {
Display.getInstance().callSerially(new Runnable(){
public void run() {
Dialog.show("Welcome", "Thanks for arriving notminimized ", "OK", null);
}
});
}
}
public void onEntered(String id) {
if(Display.getInstance().isMinimized()) {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage2");
ln.setAlertTitle("Welcome");
ln.setAlertBody("Thanks for arriving! isminimized");
Display.getInstance().scheduleLocalNotification(ln,
System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE);
} else {
Display.getInstance().callSerially(new Runnable(){
public void run() {
Dialog.show("Welcome", "Thanks for arriving
notminimized ", "OK", null);
}
});
}
}
}
【问题讨论】:
-
你的 Main 类的完整代码是什么?
标签: android ios location codenameone geofencing