Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            Battery.BatteryInfoChanged += Battery_BatteryInfoChanged;

            tLevel       = FindViewById <TextView>(Resource.Id.Level);
            tStatus      = FindViewById <TextView>(Resource.Id.Status);
            tHealth      = FindViewById <TextView>(Resource.Id.Health);
            tTemperature = FindViewById <TextView>(Resource.Id.Temperature);
            tTechnology  = FindViewById <TextView>(Resource.Id.Technology);
            tVoltage     = FindViewById <TextView>(Resource.Id.voltage);
            tPowerSource = FindViewById <TextView>(Resource.Id.Source);

            CreateNotificationChannel();

            battery = new AndroidBattery();
            UpdateBatteryInfo();

            toggleNotification         = FindViewById <ToggleButton>(Resource.Id.toggleNotification);
            toggleNotification.Checked = false;


            toggleNotification.CheckedChange += ToggleNotification_CheckedChange;

            getHistroy();



            //SetAlarmForBackgroundServices(this);
        }
Пример #2
0
        private void startNotification()
        {
            // Pass the current button press count value to the next activity:
            var valuesForActivity = new Bundle();

            valuesForActivity.PutInt(COUNT_KEY, count);

            // When the user clicks the notification, SecondActivity will start up.
            var resultIntent = new Intent(_context, typeof(MainActivity));

            // Pass some values to SecondActivity:
            resultIntent.PutExtras(valuesForActivity);

            // Construct a back stack for cross-task navigation:
            var stackBuilder = Android.App.TaskStackBuilder.Create(_context);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            var resultPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);

            AndroidBattery battery = new AndroidBattery();
            RemoteViews    R       = new RemoteViews(_context.PackageName, Resource.Layout.remoteView);

            var tLevel  = String.Format("{0}%", battery.Level);
            var tStatus = String.Format("{0}", battery.Status);


            if (Battery.State == BatteryState.Charging)
            {
                R.SetImageViewResource(Resource.Id.NotificationIcon, Resource.Drawable.volt);
                R.SetTextViewText(Resource.Id.notification_title, (tLevel + " " + tStatus + " on " + Battery.PowerSource.ToString()));
            }
            else
            {
                R.SetTextViewText(Resource.Id.notification_title, (tLevel + "  " + tStatus));
                R.SetImageViewResource(Resource.Id.NotificationIcon, Resource.Drawable.NotificationIcon);
            }


            // Build the notification:
            builder = new NotificationCompat.Builder(_context, CHANNEL_ID)
                      .SetAutoCancel(false)
                      .SetOngoing(true)                          // Dismiss the notification from the notification area when the user clicks on it
                      .SetContentIntent(resultPendingIntent)     // Start up this activity when the user clicks the intent.
                      .SetSmallIcon(Resource.Drawable.SmallIcon) // This is the icon to display
                      .SetCustomContentView(R)
                      .SetShowWhen(false)
                      .SetStyle(new NotificationCompat.DecoratedCustomViewStyle());

            // Finally, publish the notification:
            var notificationManager = NotificationManagerCompat.From(_context);

            notificationManager.Notify(NOTIFICATION_ID, builder.Build());
        }
Пример #3
0
 private void UpdateBatteryInfo()
 {
     battery           = new AndroidBattery();
     tLevel.Text       = String.Format("{0}%", battery.Level);
     tStatus.Text      = String.Format("{0}", battery.Status);
     tHealth.Text      = String.Format("{0}", battery.Health);
     tTemperature.Text = String.Format("{0} °C", battery.Temperature / 10);
     tTechnology.Text  = String.Format("{0}", battery.Technology);
     tVoltage.Text     = String.Format("{0:0.00} V", Convert.ToDecimal(battery.Voltage) / 1000);
     tPowerSource.Text = String.Format("{0}", Battery.PowerSource);
 }