2017-01-15 1 views
0

Я начал пытаться разработать приложение для Android, которое будет использоваться с новыми маячками оценки оценки, и я следовал этому руководству, чтобы показать «ввести» уведомление в диапазоне маяка. http://developer.estimote.com/android/tutorial/part-2-background-monitoring/Android Studio - уведомление об оценке маякового прогноза, не показывающее

Все установлено правильно, например 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)); 
      } 
     }); 

    } 

} 

ответ

0

Нашел причину, мне просто нужно добавить следующее в мой класс MainActivity.java:

@Override 
protected void onResume() { 
    super.onResume(); 

    SystemRequirementsChecker.checkWithDefaultDialogs(this); 
} 
Смежные вопросы