【问题标题】:Android Studio - Estimote beacon test notification not showingAndroid Studio - Estimote 信标测试通知未显示
【发布时间】:2017-01-15 11:08:38
【问题描述】:

我已经开始尝试开发一个 android 应用程序以与新的 estimote 接近信标一起使用,并且我正在按照本指南在信标范围内显示“进入”通知。 http://developer.estimote.com/android/tutorial/part-2-background-monitoring/

UUID 等所有内容都设置正确,并在 AndroidManifest.xml 文件中声明了类,但通知不起作用。也许我的代码顺序不正确?

这是 BeaconChecker.java 类(在教程中他们称之为 MyApplication.java):

package com.mcrlogs.pp.test;

/**
 * Created by usr on 15/01/2017.
 */

import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;

import java.util.List;
import java.util.UUID;


public class BeaconChecker extends Application {

    private BeaconManager beaconManager;

    public void showNotification(String title, String message) {
        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
                new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(this)
                .setSmallIcon(android.R.drawable.ic_dialog_info)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .build();
        notification.defaults |= Notification.DEFAULT_SOUND;
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notification);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        beaconManager = new BeaconManager(getApplicationContext());

        beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
            @Override
            public void onEnteredRegion(Region region, List<Beacon> list) {
                showNotification(
                        "Your gate closes in 47 minutes.",
                        "Current security wait time is 15 minutes, "
                                + "and it's a 5 minute walk from security to the gate. "
                                + "Looks like you've got plenty of time!");
            }
            @Override
            public void onExitedRegion(Region region) {
                // could add an "exit" notification too if you want (-:
            }
        });

        beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override
            public void onServiceReady() {
                beaconManager.startMonitoring(new Region(
                        "monitored region",
                        UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"),
                        null, null));
            }
        });

    }

}

【问题讨论】:

    标签: java android xml beacon estimote


    【解决方案1】:

    找到原因,我只需在我的 MainActivity.java 类中添加以下内容:

    @Override
    protected void onResume() {
        super.onResume();
    
        SystemRequirementsChecker.checkWithDefaultDialogs(this);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多