集内接近启动时的Andr​​oid GPS感应警报 [英] Android GPS Proximity Alert when starting within the set proximity

查看:143
本文介绍了集内接近启动时的Andr​​oid GPS感应警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Android的接近警报为我的车库门的应用程序。我有一个按钮设置,当pressed添加的接近警报,并开始跟踪位置。我想改变这种局面,直到跟踪要么我进入或退出附近。如果进入它会打开车库门,如果退出,将关闭车库门之后,我删除了接近警报和GPS关闭。我有工作接近完美。

问题是,当我preSS按钮,而在我的车道,因此在接近,其目的总是立即与额外KEY_PROXIMITY_ENTERING设置为进入触发。如果我开始接近的跟踪之外,它作为预期,只闪光一次我进入接近。怎么能以同样的方式工作的先发内线,当我离开的接近?在此先感谢,这是我的code。

在我的活动:

 浮动半径= 100F;
双纬度= 37.422;
双LON = -122.084;//有效期为10分钟
长的到期= 600000;的LocationManager locManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);意向意图=新意图(proximityIntentAction);的PendingIntent的PendingIntent = PendingIntent.getBroadcast(getApplicationContext(),1,意向,PendingIntent.FLAG_CANCEL_CURRENT);
locManager.addProximityAlert(纬度,经度,半径,到期的PendingIntent);

这是我的广播接收器:

 公共无效的onReceive(上下文的背景下,意图意图)
{
    Log.v(SomeTag,接近警报意图接收);
    字符串方向= LocationManager.KEY_PROXIMITY_ENTERING;
    CharSequence的文字=方向;
    INT持续时间= Toast.LENGTH_SHORT;    吐司面包= Toast.makeText(背景下,走出去+文字,持续时间);
    toast.show();
    的LocationManager locManager =(的LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
    的PendingIntent的PendingIntent = PendingIntent.getBroadcast(背景下,1,意向,PendingIntent.FLAG_NO_CREATE);
    locManager.removeProximityAlert(的PendingIntent);
}


解决方案

为什么不把上的按钮点火定时/延迟?例如,为什么不让自己的时间固定金额走出接近您的应用程序开始检测过吗?我认为,许多家庭报警以相同的方式工作。或者,另一种选择可能是检测和忽略你首次进入接近和验证任何后续的再输入到接近(即你的车库)。你觉得呢?

I would like to use Android's Proximity Alert for my garage door app. I have a button setup, that when pressed add's the proximity alert and starts tracking location. I want it to track indefinitely until I either enter or exit the proximity. If entering it will open the garage door, if exiting it will close the garage door after which I remove the proximity alert and GPS shuts off. I have it working close to perfectly.

The problem is, when I press the button while in my driveway, hence in the proximity, the intent always fires immediately with the extra KEY_PROXIMITY_ENTERING set to "entering". If I start the tracking outside of the proximity, it acts as expected, only fires once I enter the proximity. How can I get exiting the proximity when starting inside of it working in the same manner? Thanks in advance, here's my code.

In my activity:

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);

And here is my BroadcastReceiver:

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);
}

解决方案

why not put a timer/delay on the firing of the button? For example, why not allow yourself a fixed amount of time to get out of the proximity before your app starts detecting? I think that many home alarms work in the same way. Or, another option might be to detect and ignore your first entry into the proximity and validate any subsequent re-entries to that proximity (i.e. your garage). What do you think?

这篇关于集内接近启动时的Andr​​oid GPS感应警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆