Estimote / Android-Fleet-Management-SDK

Estimote Fleet Management SDK for Android
https://developer.estimote.com
MIT License
836 stars 451 forks source link

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

Open Mushtaq123 opened 5 years ago

Mushtaq123 commented 5 years ago

Prerequisites

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 https://github.com/Estimote/Android-Fleet-Management-SDK/issues/151