0

I appreciate some feedback on how to handle this:

App in foreground works fine, detects beacons and I can generate local notifications from there. When app is in background or terminated I still can bring it back to life when beacon gets in range, but that "forces" me to open the app. I would like the following behavior:

  • App should send local notification silently when detects beacons in background and not open app. My local notification should have then Intent to open app when I click them.

From here they have the correct scenario, but then the sample doesn't seem to do what should. https://altbeacon.github.io/android-beacon-library/notifications.html

Any help is much appreciated. Thank you, Bruno

1 Answers1

1

I wrote that sample, which is written in Java for Android. I can confirm it does work as shown, but on apps targeting Android 9+ you must also create a notification channel for all notifications. In Java, you can do that like this:

        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this)
                        .setContentTitle("Beacon Reference Application")
                        .setContentText("An beacon is nearby.")
                        .setSmallIcon(R.drawable.ic_launcher);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class));
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager =
                (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            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());
        }
        notificationManager.notify(1, builder.build());

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • David is it possible to run RangingBeaconsInRegion in background? In your sample I can see that you send out notification in background, but that only tells you a beacon is in range, I would like to use DidEnterRegion from my class IBootstrapNotifier that works in background to perform in that case a range, so I can read for instance URL being advertised by the beacon and trigger a notification with that URL without my app pops up. Thank you in advance for any feedback. – Bruno Teixeira Feb 14 '20 at 13:29