Android 如果禁用位置服务,则addProximityAlert不工作

Android 如果禁用位置服务,则addProximityAlert不工作,android,location,Android,Location,我正在使用LocationManageraddProximityAlert函数在用户进入某些位置的范围时向其发出警告,如果启用了位置服务,则一切正常,我会收到通知,但当位置被禁用时,我什么也得不到。即使位置未启用,我也需要接收警报,以下是我的代码: locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(Lo

我正在使用LocationManageraddProximityAlert函数在用户进入某些位置的范围时向其发出警告,如果启用了位置服务,则一切正常,我会收到通知,但当位置被禁用时,我什么也得不到。即使位置未启用,我也需要接收警报,以下是我的代码:

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
            MINIMUM_TIME_BETWEEN_UPDATE, MINIMUM_DISTANCECHANGE_FOR_UPDATE,
            new LocationListener());
public void prepareNotifications() {
// nearProductsLocs is an array of locations 
for (int i = 0; i < nearProductsLocs.length; i++) {
    Log.d(TAG, "order" + i + " " nearProductsLocs[i]);
    // +++++++++++++++++++++++++++++++++++++++++++++++++
    // add addProximityAlerts
    Location loc = nearProducts[i];
    addProximityAlert(loc.getLatitude(), loc.getLongitude());
}
}
private void addProximityAlert(Double latitude, Double longtitude, int productId) {
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra("productId", productId);
PendingIntent proximityIntent = PendingIntent.getBroadcast(
sContext.getApplicationContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(latitude, longtitude, POINT_RADIUS, PROX_ALERT_EXPIRATION,proximityIntent);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
sContext.registerReceiver(new ProximityIntentReceiver(), filter);
}

即使位置未启用,我也需要接收警报-根据定义,这是不可能的。@Commonware我指的是位置服务gps,设备仍然可以使用wifi和移动数据获取其当前位置,对吗?根据addProximityAlert的文档,在内部,此方法同时使用网络_提供程序和gps_提供程序。我的猜测是,如果没有GPS接入,它将无法工作。
public class ProximityIntentReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent xintent) {

    String key = LocationManager.KEY_PROXIMITY_ENTERING;
    Boolean entering = xintent.getBooleanExtra(key, false);
    int productId = xintent.getIntExtra("productId", 0);
    Log.d("productId", "" + productId);

    if (entering) {

        Intent offerIntent = new Intent(context, Item.class);
        offerIntent.putExtra("productId", productId);

        PendingIntent pIntent = PendingIntent.getActivity(context, productId, offerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification myNotification = new Notification(R.drawable.logo, "Nearby product!",System.currentTimeMillis());
        createNotification(myNotification);
        myNotification.setLatestEventInfo(context, "Monim", "Check this amazing Product!", pIntent);
        notificationManager.notify(productId, myNotification);
    }

}