Android 设置接近警报后,GPS将永久开启
我希望我的应用程序使用接近警报。我知道了怎么做,警报按预期工作,但有一个问题-在我设置接近警报后,GPS图标立即出现在状态栏中,并一直保持在那里,直到我重新启动设备(或关闭GPS,但一旦我重新打开GPS,它会再次出现) 即使我删除了警报,图标仍会保留在那里(它不再被触发,因此删除似乎有效)。我的第一个想法是,它将被删除,一旦它得到位置修复,但我错了 这是在运行vanilla 4.1.2 Jelly Bean的Nexus S和4.1.2 emulator上复制的 我还注意到,它似乎不会影响电池,设备会正常进入睡眠模式 以下是相关代码:Android 设置接近警报后,GPS将永久开启,android,android-location,Android,Android Location,我希望我的应用程序使用接近警报。我知道了怎么做,警报按预期工作,但有一个问题-在我设置接近警报后,GPS图标立即出现在状态栏中,并一直保持在那里,直到我重新启动设备(或关闭GPS,但一旦我重新打开GPS,它会再次出现) 即使我删除了警报,图标仍会保留在那里(它不再被触发,因此删除似乎有效)。我的第一个想法是,它将被删除,一旦它得到位置修复,但我错了 这是在运行vanilla 4.1.2 Jelly Bean的Nexus S和4.1.2 emulator上复制的 我还注意到,它似乎不会影响电池,设
public void set(Context context) {
LocationManager locationManager=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
PendingIntent pendingIntent=PendingIntent.getBroadcast(context, 0, prepareIntent(context), PendingIntent.FLAG_CANCEL_CURRENT);
double lat=getLocation().getGeoPoint().getLatitudeE6()/1e6;
double lng=getLocation().getGeoPoint().getLongitudeE6()/1e6;
locationManager.addProximityAlert(lat, lng, radius, -1, pendingIntent);
}
public void unset(Context context) {
LocationManager locationManager=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
PendingIntent pendingIntent=PendingIntent.getBroadcast(context, 0, prepareIntent(context), PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.removeProximityAlert(pendingIntent);
}
有什么问题吗?我该如何解决这个问题
更新:我做了一个小实验(设置了接近报警的50分钟睡眠模式),但结果相当混乱: 图标似乎存在,但GPS并非始终打开 有人能澄清一下这种情况吗