Skip to content

Xamarin Android - Estimote Beacons SDK initialisation fails and throws exception #296

Open
@Mushtaq123

Description

@Mushtaq123

Prerequisites

  • [X ] Put an X between the brackets on this line if you have done all of the following:
    • My Android device/devices support BLE and has Android OS version >= 4.4
    • My Android device/devices have Bluetooth enabled
    • My app has Location Permissions granted

Basic information

Estimote SDK version: [1.0.3]

Android devices affected: [Samsung S7 Edge]

Android OS version affected: [Oreo 8.0.0]

Beacon hardware version: [4.9.1]

Description

I am developing an android app using Xamarin.Android.

Estimote beacons are not detected by the SDK and throw an exception as "09-04 11:08:58.512 E/EstimoteSDK( 7625): AbstractParser.parse:33 Unable to parse scan record: You need to initialize SDK first. EstimoteSDK.initialize(applicationContext, appId, appToken)". Kindly provide a solution to resolve this issue.

Expected behavior: Need to detect the beacons

Actual behavior: throws an exception

Logs and code

[Activity(Label = "Quest Activity", MainLauncher = true)]
    public class QuestActivity : Activity, BeaconManager.IServiceReadyCallback, BeaconManager.IBeaconMonitoringListener
    {
        private BeaconManager beaconManager;

        public void OnEnteredRegion(BeaconRegion region, IList<Beacon> beacons)
        {
            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!");
        }

        public void OnExitedRegion(BeaconRegion region)
        {
            
        }

        public void OnServiceReady()
        {
            beaconManager.StartMonitoring(new BeaconRegion(
                "monitored region",
                "B9407F30-F5F8-466E-AFF9-25556B57FE6D",
                22504, 48827));
        }

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //EstimoteSdk.initialize(applicationContext, appId, appToken);

            beaconManager = new BeaconManager(ApplicationContext);
            beaconManager.Connect(this);
            beaconManager.SetBeaconMonitoringListener(this);
        }

        protected override void OnResume()
        {
            SystemRequirementsChecker.CheckWithDefaultDialogs(this);
            base.OnResume();
        }

        void ShowNotification(string title, string message)
        {
            try
            {
                #region Intent
                var intent = new Intent(this, typeof(MainActivity));
                intent.AddFlags(ActivityFlags.ClearTop);
                var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);
                #endregion

                #region Notification Style
                Notification.BigTextStyle textStyle = new Notification.BigTextStyle();
                textStyle.SetBigContentTitle(title);
                textStyle.BigText(message);
                #endregion

                Notification.Builder notificationBuilder = null;
                NotificationManager mNotificationManager = (NotificationManager)ApplicationContext.GetSystemService(NotificationService);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    string CHANNEL_ID = "my_channel_01";// The id of the channel. 
                    NotificationImportance importance = NotificationImportance.High;
                    NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, title, importance);
                    mChannel.EnableVibration(true);
                    mNotificationManager.CreateNotificationChannel(mChannel);

                    notificationBuilder = new Notification.Builder(this, CHANNEL_ID);
                }
                else
                    notificationBuilder = new Notification.Builder(this);

                //RingtoneType.Alarm
                //RingtoneType.All
                //RingtoneType.Ringtone
                //RingtoneType.Notification

                notificationBuilder.SetStyle(textStyle)
                                   .SetContentTitle(title)
                                   .SetContentText(message)
                                   .SetAutoCancel(true)
                                   .SetContentIntent(pendingIntent);

                if (notificationBuilder != null)
                {
                    mNotificationManager.Notify(0, notificationBuilder.Build());
                }
            }
            catch (Exception ex)
            {
            }
        }
    }

this issue is already reported in GitHub and find the same in below link
#151

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions