Я недавно пытаюсь создать приложение, которое использует библиотеку AltBeacon.
Проблема, с которой я сейчас сталкиваюсь, заключается в следующем: я создал класс Application следующим образом:
beaconManager = beaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().clear();
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.setRegionStatePersistenceEnabled(false);
Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.drawable.icon);
builder.setBadgeIconType(Notification.BADGE_ICON_NONE);
Intent buttonIntent = new Intent(getApplicationContext(), ButtonReceiver.class);
buttonIntent.putExtra("notificationId",NOTIFICATION_ID);
PendingIntent btPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, buttonIntent,0);
builder.addAction(R.drawable.stop,"Termina Rilevamento.", btPendingIntent);
builder.setColor(getResources().getColor(R.color.mygreen));
builder.setContentIntent(btPendingIntent);
builder.setPriority(Notification.PRIORITY_MAX);
builder.setContentTitle("Rilevazione autenticazione in corso.");
Intent intent = new Intent(this, LoginActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT
);
builder.setContentIntent(pendingIntent);
NotificationChannel channel = new NotificationChannel("My Notification Channel ID",
"My Notification Name", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("My Notification Channel Description");
NotificationManager notificationManager = (NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
builder.setChannelId(channel.getId());
beaconManager.enableForegroundServiceScanning(builder.build(), 456);
beaconManager.setEnableScheduledScanJobs(false);
beaconManager.setBackgroundBetweenScanPeriod(0);
beaconManager.setBackgroundScanPeriod(1100);
Region region = new Region("Region iniziale",null,Identifier.parse("789"),null);
regionBootstrap = new RegionBootstrap(this, region);
backgroundPowerSaver = new BackgroundPowerSaver(this);
Где Button в уведомлении указывает на класс BroadCastReceiver, который является ButtonReceiver,В приемнике кнопки я хочу выполнить действие по отключению службы переднего плана и закрыть приложение.Я делаю это следующим образом:
int notificationId = intent.getIntExtra("notificationId", 0);
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(notificationId);
AndroidWalkEnrollmentApplication prova = new AndroidWalkEnrollmentApplication();
prova.disableMonitoring();
внутри метода onReceive ().
Итак, проблема в следующем: в disableMonitoring () я следую примеру Android-Beacon-Reference и поэтому для отключения сканирования переднего плана я делаю: bootstrap.disable () и bootstrap = null.Проблема в том, что, кажется, не работает.Когда я нажимаю кнопку внутри уведомления в режиме переднего плана, он отключается.Я также попытался выполнить Beaconmanager.disableForegroundService (), но на самом деле он не отключен.
Есть подсказка?