我想为我的车库门应用使用Android的Proximity Alert。我有一个按钮设置,当按下添加的接近警报并开始跟踪位置。我希望它无限期地跟踪,直到我进入或退出接近度。如果进入它将打开车库门,如果退出它将关闭车库门,之后我删除接近警报和GPS关闭。我的工作接近完美。在接近设置的情况下启动Android GPS Proximity Alert
问题是,当我在车道上按下按钮时,因此在附近,意图总是立即触发,额外的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版本。 – Yaadm 2015-11-11 17:27:29