나는이 비컨 개념에 매우 익숙하다. 데모 목적을 위해이 샘플 응용 프로그램 Android iBeacon App을 사용하여 신호/추정치 중 하나를 구성했습니다.Xamarin.Android에서 여러 Estimote/비콘
여기서 애플리케이션은 한 번에 하나의 비컨을 찾을 수 있습니다. 단일 비컨의 UUID를 전달해야만 비컨 범위 내에 있는지 여부를 확인할 수 있습니다. 동일한 응용 프로그램을 사용하여 여러 개의 비컨을 찾을 가능성이 있습니까? 사용자가 특정 신호 범위를 입력하면 사용자는 특정 신호에 대한 알림을 받아야합니다. 그래서 여러 비콘을 추가 할 수있는 가능성이 있습니까 ..? 비컨의 UUID를 기준으로하면 비컨의 범위를 구분해야합니다.. 좋은 튜토리얼이나 수정 방법을 안내 할 수있는 사람은 없습니까? 어떤 도움이 많이 여기
내 MainActivity.csusing System.Linq;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Views;
using Android.Widget;
using Android.OS;
using RadiusNetworks.IBeaconAndroid;
using Color = Android.Graphics.Color;
using Android.Bluetooth;
namespace FindTheMonkey.Droid
{
[Activity(Label = "Estimote", MainLauncher = true, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : Activity, IBeaconConsumer
{
private const string UUID = "78540181-ea7f-fc83-2d61-4031622455b6";
private const string UUID1 = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
private const string UUID2 = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
private const string monkeyId = "blueberry";
bool _paused;
private BluetoothManager _manager;
View _view;
IBeaconManager _iBeaconManager;
MonitorNotifier _monitorNotifier;
RangeNotifier _rangeNotifier;
Region _monitoringRegion;
Region _rangingRegion;
TextView _text;
int _previousProximity;
public MainActivity()
{
_iBeaconManager = IBeaconManager.GetInstanceForApplication(this);
_monitorNotifier = new MonitorNotifier();
_rangeNotifier = new RangeNotifier();
_monitoringRegion = new Region(monkeyId, UUID, null, null);
_rangingRegion = new Region(monkeyId, UUID, null, null);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
_view = FindViewById<RelativeLayout>(Resource.Id.findTheMonkeyView);
_text = FindViewById<TextView>(Resource.Id.monkeyStatusLabel);
_iBeaconManager.Bind(this);
_monitorNotifier.EnterRegionComplete += EnteredRegion;
_monitorNotifier.ExitRegionComplete += ExitedRegion;
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
}
protected override void OnResume()
{
_manager = (BluetoothManager)Application.Context.GetSystemService(BluetoothService);
_manager.Adapter.Enable();
base.OnResume();
_paused = true;
}
protected override void OnPause()
{
base.OnPause();
_paused = true;
}
void EnteredRegion(object sender, MonitorEventArgs e)
{
if(_paused)
{
ShowNotification();
}
}
void ExitedRegion(object sender, MonitorEventArgs e)
{
if (_paused)
{
ShowNotification1();
UpdateDisplay("There are no beacons around you.!", Color.Black);
}
}
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
if (e.Beacons.Count > 0)
{
var beacon = e.Beacons.FirstOrDefault();
var message = string.Empty;
switch((ProximityType)beacon.Proximity)
{
case ProximityType.Immediate:
UpdateDisplay("You found the Estimote!", Color.Green);
break;
case ProximityType.Near:
UpdateDisplay("You're getting warmer", Color.Yellow);
break;
case ProximityType.Far:
UpdateDisplay("You're freezing cold", Color.Blue);
break;
case ProximityType.Unknown:
UpdateDisplay("I'm not sure how close you are to the Estimote", Color.Red);
break;
}
_previousProximity = beacon.Proximity;
}
}
#region IBeaconConsumer impl
public void OnIBeaconServiceConnect()
{
_iBeaconManager.SetMonitorNotifier(_monitorNotifier);
_iBeaconManager.SetRangeNotifier(_rangeNotifier);
_iBeaconManager.StartMonitoringBeaconsInRegion(_monitoringRegion);
_iBeaconManager.StartRangingBeaconsInRegion(_rangingRegion);
}
#endregion
private void UpdateDisplay(string message, Color color)
{
RunOnUiThread(() =>
{
_text.Text = message;
_view.SetBackgroundColor(color);
});
}
private void ShowNotification()
{
var resultIntent = new Intent(this, typeof(MainActivity));
resultIntent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
var notificationId = Resource.String.monkey_notification;
var builder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Xamarin_Icon)
.SetContentTitle(this.GetText(Resource.String.app_label))
.SetContentText(this.GetText(Resource.String.monkey_notification))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true);
var notification = builder.Build();
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(notificationId, notification);
}
private void ShowNotification1()
{
var resultIntent = new Intent(this, typeof(MainActivity));
resultIntent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
var notificationId = Resource.String.monkey_notification1;
var builder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Xamarin_Icon)
.SetContentTitle(this.GetText(Resource.String.app_label))
.SetContentText(this.GetText(Resource.String.monkey_notification1))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true);
var notification = builder.Build();
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(notificationId, notification);
}
protected override void OnDestroy()
{
base.OnDestroy();
_monitorNotifier.EnterRegionComplete -= EnteredRegion;
_monitorNotifier.ExitRegionComplete -= ExitedRegion;
_rangeNotifier.DidRangeBeaconsInRegionComplete -= RangingBeaconsInRegion;
_iBeaconManager.StopMonitoringBeaconsInRegion(_monitoringRegion);
_iBeaconManager.StopRangingBeaconsInRegion(_rangingRegion);
_iBeaconManager.UnBind(this);
}
}
}
입니다 .. 감사하겠습니다
EDIT1 :내가 통지를 트리거하기 위해 이런 식으로 뭔가를 시도했다 사용자가 비콘의 다른 영역을 입력 할 때. 그러나 동일한 비 통지가 두 비컨 모두를 위해 트리거 될 때마다 .i mea n 사용자가 영역을 입력하면 ShowNotification()이 호출 될 때마다 ShowNotification1()이 호출되고 사용자가 영역을 종료하면 ShowNotification1()이 호출됩니다.
사용자가 지역을 입력 할 때 다른 비컨에 대한 다른 알림을 호출하는 방법 ..?
namespace FindTheMonkey.Droid
{
[Activity(Label = "Estimote", MainLauncher = true, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : Activity, IBeaconConsumer
{
private const string UUID = "78540181-ea7f-fc83-2d61-4031622455b6";
private const string monkeyId = "blueberry";
private const int major = 26110;
private const int minor = 16681;
private const string UUID1 = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
private const string monkeyId1 = "mint";
private const int major1 = 62068;
private const int minor1 = 28983;
bool _paused;
private BluetoothManager _manager;
View _view;
IBeaconManager _iBeaconManager;
MonitorNotifier _monitorNotifier;
RangeNotifier _rangeNotifier;
Region _monitoringRegion;
Region _rangingRegion;
IBeaconManager _iBeaconManager1;
MonitorNotifier _monitorNotifier1;
RangeNotifier _rangeNotifier1;
Region _monitoringRegion1;
Region _rangingRegion1;
TextView _text;
int _previousProximity;
public MainActivity()
{
_iBeaconManager = IBeaconManager.GetInstanceForApplication(this);
_monitorNotifier = new MonitorNotifier();
_rangeNotifier = new RangeNotifier();
_monitoringRegion = new Region(monkeyId, UUID, Integer.ValueOf(major), Integer.ValueOf(minor));
_rangingRegion = new Region(monkeyId, UUID, Integer.ValueOf(major), Integer.ValueOf(minor));
_iBeaconManager1 = IBeaconManager.GetInstanceForApplication(this);
_monitorNotifier1 = new MonitorNotifier();
_rangeNotifier1 = new RangeNotifier();
_monitoringRegion1 = new Region(monkeyId1, UUID1, Integer.ValueOf(major1), Integer.ValueOf(minor1));
_rangingRegion1 = new Region(monkeyId1, UUID1, Integer.ValueOf(major1), Integer.ValueOf(minor1));
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
_view = FindViewById<RelativeLayout>(Resource.Id.findTheMonkeyView);
_text = FindViewById<TextView>(Resource.Id.monkeyStatusLabel);
_iBeaconManager.Bind(this);
_monitorNotifier.EnterRegionComplete += EnteredRegion;
_monitorNotifier.ExitRegionComplete += ExitedRegion;
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
_iBeaconManager1.Bind(this);
_monitorNotifier1.EnterRegionComplete += EnteredRegion1;
_monitorNotifier1.ExitRegionComplete += ExitedRegion1;
_rangeNotifier1.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
}
protected override void OnResume()
{
_manager = (BluetoothManager)Application.Context.GetSystemService(BluetoothService);
_manager.Adapter.Enable();
base.OnResume();
_paused = true;
}
protected override void OnPause()
{
base.OnPause();
_paused = true;
}
void EnteredRegion(object sender, MonitorEventArgs e)
{
if(_paused)
{
ShowNotification();
}
}
void ExitedRegion(object sender, MonitorEventArgs e)
{
if (_paused)
{
ShowNotification1();
UpdateDisplay("There are no beacons around you.!", Color.Black);
}
}
void EnteredRegion1(object sender, MonitorEventArgs e)
{
if (_paused)
{
ShowNotification2();
}
}
void ExitedRegion1(object sender, MonitorEventArgs e)
{
if (_paused)
{
ShowNotification3();
UpdateDisplay("There are no beacons around you.!", Color.Black);
}
}
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
if (e.Beacons.Count > 0)
{
var beacon = e.Beacons.FirstOrDefault();
var message = string.Empty;
switch((ProximityType)beacon.Proximity)
{
case ProximityType.Immediate:
UpdateDisplay("You found the Estimote!", Color.Green);
break;
case ProximityType.Near:
UpdateDisplay("You're getting warmer", Color.Yellow);
break;
case ProximityType.Far:
UpdateDisplay("You're freezing cold", Color.Blue);
break;
case ProximityType.Unknown:
UpdateDisplay("I'm not sure how close you are to the Estimote", Color.Red);
break;
}
_previousProximity = beacon.Proximity;
}
}
#region IBeaconConsumer impl
public void OnIBeaconServiceConnect()
{
_iBeaconManager1.SetMonitorNotifier(_monitorNotifier1);
_iBeaconManager1.SetRangeNotifier(_rangeNotifier1);
_iBeaconManager1.StartMonitoringBeaconsInRegion(_monitoringRegion1);
_iBeaconManager1.StartRangingBeaconsInRegion(_rangingRegion1);
_iBeaconManager.SetMonitorNotifier(_monitorNotifier);
_iBeaconManager.SetRangeNotifier(_rangeNotifier);
_iBeaconManager.StartMonitoringBeaconsInRegion(_monitoringRegion);
_iBeaconManager.StartRangingBeaconsInRegion(_rangingRegion);
}
#endregion
private void UpdateDisplay(string message, Color color)
{
RunOnUiThread(() =>
{
_text.Text = message;
_view.SetBackgroundColor(color);
});
}
private void ShowNotification()
{
var resultIntent = new Intent(this, typeof(MainActivity));
resultIntent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
var notificationId = Resource.String.monkey_notification;
var builder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Xamarin_Icon)
.SetContentTitle(this.GetText(Resource.String.app_label))
.SetContentText(this.GetText(Resource.String.monkey_notification))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true);
var notification = builder.Build();
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(notificationId, notification);
}
private void ShowNotification2()
{
var resultIntent = new Intent(this, typeof(MainActivity));
resultIntent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
var notificationId = Resource.String.monkey_notification2;
var builder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Xamarin_Icon)
.SetContentTitle(this.GetText(Resource.String.app_label))
.SetContentText(this.GetText(Resource.String.monkey_notification2))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true);
var notification = builder.Build();
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(notificationId, notification);
}
private void ShowNotification1()
{
var resultIntent = new Intent(this, typeof(MainActivity));
resultIntent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
var notificationId = Resource.String.monkey_notification1;
var builder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Xamarin_Icon)
.SetContentTitle(this.GetText(Resource.String.app_label))
.SetContentText(this.GetText(Resource.String.monkey_notification1))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true);
var notification = builder.Build();
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(notificationId, notification);
}
private void ShowNotification3()
{
var resultIntent = new Intent(this, typeof(MainActivity));
resultIntent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);
var notificationId = Resource.String.monkey_notification3;
var builder = new Notification.Builder(this)
.SetSmallIcon(Resource.Drawable.Xamarin_Icon)
.SetContentTitle(this.GetText(Resource.String.app_label))
.SetContentText(this.GetText(Resource.String.monkey_notification3))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true);
var notification = builder.Build();
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(notificationId, notification);
}
protected override void OnDestroy()
{
base.OnDestroy();
_monitorNotifier.EnterRegionComplete -= EnteredRegion;
_monitorNotifier.ExitRegionComplete -= ExitedRegion;
_rangeNotifier.DidRangeBeaconsInRegionComplete -= RangingBeaconsInRegion;
_iBeaconManager.StopMonitoringBeaconsInRegion(_monitoringRegion);
_iBeaconManager.StopRangingBeaconsInRegion(_rangingRegion);
_iBeaconManager.UnBind(this);
_monitorNotifier1.EnterRegionComplete -= EnteredRegion1;
_monitorNotifier.ExitRegionComplete -= ExitedRegion1;
_rangeNotifier1.DidRangeBeaconsInRegionComplete -= RangingBeaconsInRegion;
_iBeaconManager1.StopMonitoringBeaconsInRegion(_monitoringRegion1);
_iBeaconManager1.StopRangingBeaconsInRegion(_rangingRegion1);
_iBeaconManager1.UnBind(this);
_manager.Adapter.Disable();
}
}
}
예 ..이 기능은 물론 작동하지만 사용자가 신호의 범위에 도달하면 다른 신호에 대해 다른 알림을 트리거하는 아이디어가 있습니까? –
사용자가 두 번째 비콘 범위에 도달했을 때와 다른 알림이 트리거해야하는 첫 번째 비콘 범위에 들어간 경우 .. 비컨을 구분하고 알림을 트리거하는 방법은 무엇입니까? –
RangeEventArgs에는 조사 할 수있는 Region 속성이있어 트리거 된 여러 영역 중 어느 것이 있는지 확인할 수 있습니다. – davidgyoung