Example #1
0
        public override void OnCreate()
        {
            base.OnCreate();

            Profiler.Start("OnResume");
            CrossCurrentActivity.Current.Init(this);

            //Set the default notification channel for your app when running Android Oreo
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }

            FirebasePushNotificationManager.Initialize(this, false);

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                if (Xamarin.Forms.Application.Current == null || !IsInForeground())
                {
                    bool isAlarmActive = Preferences.Get(Constants.PreferenceAlarmActivate, Constants.PreferenceAlarmActivateDefault);
                    var  operation     = OperationHelper.MapFirebaseToOperation(p.Data);
                    if (isAlarmActive && p.Data != null)
                    {
                        Intent intent = new Intent(this, typeof(MainActivity));
                        intent.PutExtra(INTENT_EXTRA_OPERATION, JsonConvert.SerializeObject(operation));
                        StartActivity(intent);
                    }
                }
            };
        }
Example #2
0
        public App()
        {
            SetUpAppCenter();

            DependencyService.Register <IDataStore <Operation>, OperationDataStore>();

            if (!DesignMode.IsDesignModeEnabled)
            {
                VersionTracking.Track();
            }

            InitializeComponent();

            MainPage = new NavigationPage(new OperationsPage());

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Push Forms: OnNotificationReceived");
                bool isAlarmActive = Preferences.Get(Constants.PreferenceAlarmActivate, Constants.PreferenceAlarmActivateDefault);
                var  operation     = OperationHelper.MapFirebaseToOperation(p.Data);
                if (isAlarmActive && operation != null)
                {
                    PushOperationAsync(operation);
                }
            };

            CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
            {
                // Notification is opened (probably from iOS)
                System.Diagnostics.Debug.WriteLine("Push Forms: OnNotificationOpened");
                var operation = OperationHelper.MapFirebaseToOperation(p.Data);
                if (operation != null)
                {
                    PushOperationAsync(operation, true);
                }
            };

            CrossFirebasePushNotification.Current.OnNotificationAction += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Push Forms: OnNotificationAction");

                if (!string.IsNullOrEmpty(p.Identifier))
                {
                    System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
                    foreach (var data in p.Data)
                    {
                        System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                    }
                }
            };
        }