Android Proximity Alert不会激发

时间:2018-04-06 19:35:04

标签: android broadcastreceiver proximity

我尝试在下面设置Proximity警报是我的代码,但它没有触发

Intent intent = new Intent("com.example.mycomputer.xxx.Util.ProximityIntentReceiver");
IntentFilter filter = new IntentFilter("com.example.mycomputer.xxx.Util.ProximityIntentReceiver");
PendingIntent proximityIntent;
requestcodex=1;

for (int i = 1; i <= 10; i++) {
    proximityIntent = PendingIntent.getBroadcast(getContext(), requestcodex , intent, 0);
    locationManager.addProximityAlert(Database.LatLngTest[i][1], Database.LatLngTest[i][2], Rd, -1, proximityIntent);
    requestcodex++;
    getContext().registerReceiver(new ProximityIntentReceiver(), filter);
}

我发送Mock位置以测试真实设备模拟位置是否遵循正确路径但是广播侦听器未被调用

ProximityIntentReceiver

public class ProximityIntentReceiver extends BroadcastReceiver {
static int NOTIFICATION_ID = 1000 ;
int id = NOTIFICATION_ID;
boolean noti = false;

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

    String key = LocationManager.KEY_PROXIMITY_ENTERING;
    Boolean entering = intent.getBooleanExtra(key, false);
    String msg;
    if (entering) {
        msg = "Entering ";
        noti = true;

    } else {
        msg = "Exiting ";
        noti = true;
    }

    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context,requestcodex, notificationIntent, 0);
    final Notification notification = createNotification();


    notification.contentIntent = pendingIntent;
    notificationManager.notify(NOTIFICATION_ID, notification);


    if (id == NOTIFICATION_ID) {
            //Build Dialog

    }
}



private Notification createNotification() {
    // Notification       
    return notification;
   }
}

谢谢!!!

0 个答案:

没有答案
相关问题