1
这是我的第一个问题:Android的接近警戒不被解雇
我试图接近配置警报将从数据库和互联网服务提供商食。但我在配置简单的近距离警报进行测试时遇到问题。我设法创建警报,但它永远不会被解雇,我现在只在模拟器中尝试,并且不知道是否需要一些额外的代码来触发警报。
我读过的地方,GPS供应商禁用,使网络供应商可以用来触发模拟器上的警报。
我的代码如下所示:
接近意向声明
private String proximityIntentAction = new String("gpsdelivery.gpship.getLocation.GPS_PROXIMITY_ALERT");
内部在onStart(),其中的警报参数设置
IntentFilter intentFilter = new IntentFilter(proximityIntentAction);
registerReceiver(new ProximityAlert(), intentFilter);
setProximityAlert(45.150344, 9.999815, -1);
接近警报功能在警报得到已创建
private void setProximityAlert(double lat, double lon, int requestCode)
{
// 100 meter radius
float radius = 100f;
// Expiration is 10 Minutes
long expiration = 600000;
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(proximityIntentAction);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
locManager.addProximityAlert(lat, lon, radius, expiration, pendingIntent);
}
最后我接近与广播接收机警报类
public class ProximityAlert extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.v("SomeTag","Proximity alert received");
}
}
请让我知道我缺少什么或者我做错了。在此先感谢,任何源代码将不胜感激。
为什么你认为你应该广播接近警报?你在DDMS的模拟器中设置了一个位置吗? – Falmarri 2010-10-05 23:37:23
我认为广播接收机需要它来执行接近警报被触发后的动作,至少这是我在其他示例中看到的。我确实在DDMS中的邻近范围内设置了多个位置,但警报永远不会被触发,我得到了这个错误信息:10-07 01:22:50.681:ERROR/ActivityThread(796):android.app.IntentReceiverLeaked:Activity gpsdelivery.gpship .getLocation泄漏了最初在此处注册的IntentReceiver gpsdel[email protected]。你是否错过了对unregisterReceiver()的调用? – flavs 2010-10-07 05:58:06