【问题标题】:Android GPS Proximity Alert when starting within the set proximityAndroid GPS Proximity Alert 在设定的距离内启动时发出警报
【发布时间】:2011-12-19 01:39:57
【问题描述】:

我想为我的车库门应用使用 Android 的 Proximity Alert。我有一个按钮设置,按下时添加接近警报并开始跟踪位置。我希望它无限期地跟踪,直到我进入或退出邻近区域。如果进入它将打开车库门,如果退出它将关闭车库门,然后我移除接近警报并且 GPS 关闭。我让它工作得近乎完美。

问题是,当我在车道上按下按钮时,因此在附近时,意图总是立即触发,并将额外的 KEY_PROXIMITY_ENTERING 设置为“进入”。如果我在邻近区域之外开始跟踪,它会按预期运行,只有在我进入邻近区域时才会触发。当以相同的方式在其中开始工作时,我怎样才能退出邻近?提前致谢,这是我的代码。

在我的活动中:

float radius = 100f;
double lat = 37.422;
double lon = -122.084;

// Expiration is 10 Minutes
long expiration = 600000;

LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

Intent intent = new Intent(proximityIntentAction);

PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
locManager.addProximityAlert(lat, lon, radius, expiration, pendingIntent);

这是我的广播接收器:

public void onReceive(Context context, Intent intent)
{
    Log.v("SomeTag","Proximity Alert Intent Received");
    String direction = LocationManager.KEY_PROXIMITY_ENTERING;
    CharSequence text = direction;
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, "going: "+text, duration);
    toast.show();
    LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_NO_CREATE);
    locManager.removeProximityAlert(pendingIntent);
}

【问题讨论】:

  • 我遇到了同样的问题。过去,它对我有用,正如您所期望的那样,如果在我离开附近时注册接近度现在立即用 isEntering=false 触发,它根本不会触发。 ---- 我只需要知道它的设备是特定的还是来自某个 android 版本。

标签: android gps locationmanager proximity


【解决方案1】:

为什么不在按钮的触发上设置一个计时器/延迟?例如,为什么不在您的应用开始检测之前让自己有一段固定的时间离开附近?我认为许多家庭警报器的工作方式相同。或者,另一种选择可能是检测并忽略您第一次进入邻近区域并验证任何后续重新进入该邻近区域(即您的车库)。你怎么看?

【讨论】:

  • 这是一个很好的建议。当我启动接近警报时,我也遇到了延迟......
猜你喜欢
  • 1970-01-01
  • 2014-12-03
  • 1970-01-01
  • 2010-11-20
  • 1970-01-01
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多