Geofenceの例をローカル通知を設定するcn1でテストしました。アプリが閉じる(破棄される)と、アプリはまだ通知を出します。しかし、私はGPSを介して場所を取得し、それらをサーバーに保存するconnectionRequestを実行したい。私は次のコードでLocalNotificationの代わりにconnectionRequestコードを置き換えましたが、それは動作しません。ユーザーが一度インストールして閉じる(破棄する)と、アプリが自分の位置情報をサーバーに永久に送信するように、アプリケーションが閉じられたときに(最小化されているが破棄されていないとき)、connectionRequestを実行するにはどうすればよいですかアンインストールされます。アプリがバックグラウンドにあるときのConnectionRequest
Geofence gf = new Geofence( "test"、loc、100、100000); LocationManager.getLocationManager()。addGeoFencing(GeofenceListenerImpl.class、gf); localNotificationと
ジオフェンス:
public class GeofenceListenerImpl implements GeofenceListener {
@Override
public void onExit(String id) {
}
@Override
public void onEntered(String id) {
if(Display.getInstance().isMinimized()) {
Display.getInstance().callSerially(() -> {
Dialog.show("Welcome", "Thanks for arriving", "OK", null);
});
} else {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage");
ln.setAlertTitle("Welcome");
ln.setAlertBody("Thanks for arriving!");
Display.getInstance().scheduleLocalNotification(ln, 10, LocalNotification.REPEAT_NONE);
}
}
}
なぜ次doesnotの仕事? (アプリケーションが実行されているとき、または最小化されているときにのみ機能するが、破壊されていないときにのみ機能する。)
PS。バックグラウンドフェッチを使用しましたが、アプリが最小化されている場合にのみ機能します。
アップデート1:私は最小限の外でconnectionRequestを使用する方法のデモ()メソッド...
public class GeofenceListenerImpl implements GeofenceListener {
@Override
public void onExit(String id) {
System.out.println("geofence onExit");
}
@Override
public void onEntered(String id) {
if(Display.getInstance().isMinimized()) {
Display.getInstance().callSerially(() -> {
});
} else {
System.out.println("geofence when app is closed");
Connection c = new Connection();
c.liveTrackConnectionMethod("22" , "23");
}
}
}
Connectionクラス
public class Connection {
ArrayList<Map<String, Object>> response;
public void liveTrackConnectionMethod(String lat, String lon) {
ConnectionRequest cr = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser jSONParser = new JSONParser();
Map parser = jSONParser.parseJSON(new InputStreamReader(input));
response = null;
}
};
cr.setPost(true);
cr.setUrl("http://url.com");
cr.addArgument("userid", Preferences.get(AllUrls.userIdPreference, null));
cr.addArgument("lat", lat + "");
cr.addArgument("long", lon + "");
cr.addRequestHeader("Accept", "application/json");
NetworkManager.getInstance().addToQueueAndWait(cr);
}
}
'c.liveTrackConnectionMethod(" 22 "、" 23 ");' ifelseの外で動作しますか? – Diamond
それは内部で働く... – beck