【问题标题】:Receive notification from beacon region detection during background monitoring在后台监控期间接收来自信标区域检测的通知
【发布时间】:2015-08-25 09:05:52
【问题描述】:

我正在尝试创建一个基本应用程序,其中我创建了一个 regionBootstrap 用于对各种类型的信标进行后台监控,就像在参考应用程序中一样。

但是,我不想在进入信标区域时将应用程序置于前台,而是简单地显示“您已进入信标区域”本地通知。

我认为这需要在“扩展应用程序实现 BootStrapNotifier”类的 onCreate 方法中进行编码。但我也看到启动主要活动的意图是在 didEnterRegion 方法中实例化的,那么这实际上是我需要编写通知的地方吗?

【问题讨论】:

    标签: ibeacon ibeacon-android android-ibeacon eddystone eddystone-url


    【解决方案1】:

    触发后台通知的最简单方法是创建一个实现BootstrapNotifier 的自定义Application 类。然后将通知代码放在didEnterRegion 回调方法中,如下所示:

    @Override
    public void didEnterRegion(Region arg0) {
        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this)
                        .setContentTitle("Beacon Reference Application")
                        .setContentText("A 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);
        notificationManager.notify(1, builder.build());
    
    }
    

    您可以在reference application 中看到关于Android Beacon Library 的完整示例。

    【讨论】:

      猜你喜欢
      • 2015-02-07
      • 2017-03-10
      • 2014-08-30
      • 1970-01-01
      • 2016-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多