【问题标题】:Xamarin.Forms (AltBeacon Android Library) - Send local notification when detected beacon in background [duplicate]Xamarin.Forms(AltBeacon Android Library)-在后台检测到信标时发送本地通知[重复]
【发布时间】:2020-02-10 23:00:28
【问题描述】:

感谢有关如何处理此问题的一些反馈:

前台应用程序工作正常,检测到信标,我可以从那里生成本地通知。当应用程序处于后台或终止时,当信标进入范围内时,我仍然可以使其恢复活力,但这“迫使”我打开应用程序。我想要以下行为:

  • 当在后台检测到信标并且未打开应用程序时,应用程序应静默发送本地通知。当我点击它们时,我的本地通知应该有打开应用程序的意图。

从这里他们有正确的场景,但是示例似乎没有做应该做的事情。 https://altbeacon.github.io/android-beacon-library/notifications.html

非常感谢任何帮助。 谢谢, 布鲁诺

【问题讨论】:

    标签: android notifications local altbeacon


    【解决方案1】:

    我编写了那个示例,它是用 Java 为 Android 编写的。我可以确认它确实如图所示工作,但在针对 Android 9+ 的应用程序上,您还必须为所有通知创建一个通知通道。在 Java 中,您可以这样做:

            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());
    
    

    【讨论】:

    • David 是否可以在后台运行 RangingBeaconsInRegion?在您的示例中,我可以看到您在后台发送通知,但这仅告诉您信标在范围内,我想使用我的 IBootstrapNotifier 类中的 DidEnterRegion 在后台工作以在这种情况下执行范围,所以我可以例如,读取信标发布的 URL 并使用该 URL 触发通知,而不会弹出我的应用程序。提前感谢您的任何反馈。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2015-11-16
    • 1970-01-01
    • 2014-10-03
    相关资源
    最近更新 更多