0

I am creating an application for myself, and I need my service to work when the device is rebooted. I did it here is my code.

namespace Corporate_messenger.Droid.Broadcast
{
    [BroadcastReceiver(Name = "com.companyname.corporate_messenger.BootReceiver", Enabled = true, Exported = true)]
    [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
    public class BootReceiver : BroadcastReceiver
    {
        private void Start1(Context context)
        {
            Intent mycallIntent = new Intent(context, typeof(MainActivity));

            mycallIntent.AddFlags(ActivityFlags.NewTask);

           


            Android.App.Application.Context.StartActivity(mycallIntent);
        }
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
               

              
                var intentService = new Intent(context, typeof(NotoficationService));
                if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                {
                    SpecialData.RestartResponse = true;
                    context.StartForegroundService(intentService);

                }
                else
                {
                    context.StartService(intentService);
                    // Flag_On_Off_Service = true;
                }
            }
            catch(Exception ex)
            {
                Log.Error("MyLog", ex.Message);

            }


        } // OnReceive
    }
}

I also requested permissions to work with folders and microphone. My cod - Permission

 public async Task Permission()
        {
            
            var PermissionsStrorage_Write = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();

            var PermissionsInternet = await Permissions.CheckStatusAsync<Permissions.NetworkState>();

            var PermissionsStrorage_Read = await Permissions.CheckStatusAsync<Permissions.StorageRead>();

            var PermissionsRecord = await Permissions.CheckStatusAsync<Permissions.Microphone>();
            if (PermissionsInternet != PermissionStatus.Granted)
            {
                PermissionsInternet = await Permissions.RequestAsync<Permissions.NetworkState>();

            }
            
            if (PermissionsRecord != PermissionStatus.Granted)
            {
                PermissionsRecord = await Permissions.RequestAsync<Permissions.Microphone>();

            }
          
            if (PermissionsStrorage_Write != PermissionStatus.Granted && PermissionsStrorage_Read != PermissionStatus.Granted)
            {
                PermissionsStrorage_Write = await Permissions.RequestAsync<Permissions.StorageWrite>();
                PermissionsStrorage_Read = await Permissions.RequestAsync<Permissions.StorageRead>();
            }
            if (PermissionsStrorage_Write != PermissionStatus.Granted && PermissionsStrorage_Read != PermissionStatus.Granted)
            {
                return;
            }
        }

Result code: ResultCode But I ran into a problem, which is that for my service to work correctly on some devices, two checkboxes are required. Here's a picture 2 checkboxes

Now I don't understand how to ask the user about these permissions so that he doesn't have to go into the settings himself. Perhaps the application could open this page on its own.Basically , this problem occurs on xiaomi phone. At the moment I am writing an application for android. But xamarin allows you to write code for iOS, so in the future I will also add such functions there.

1 Answers1

1

here is the answer to this question

 private void SetSetting()
        {
           
            // Manufacturer (Samsung)
            var manufacturer = DeviceInfo.Manufacturer.ToLower();
            switch (manufacturer)
            {
                case "xiaomi":
                    SetPermission("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsConfigActivity");
                    break;
                case "huawei":
                    SetPermission("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity");
                    break;
                case "samsung":
                    if(Battery.EnergySaverStatus == EnergySaverStatus.On)
                        SetPermission("com.samsung.android.lool", "com.samsung.android.sm.battery.ui.BatteryActivity");
                    break;
            }
           
        }

        private void SetPermission(string param1,string param2)
        {
            try
            {
                Intent intent = new Intent();
                intent.SetComponent(new ComponentName(param1, param2));
                // intent.SetComponent(new ComponentName("com.miui.securitycenter", "com.miui.appmanager.ApplicationsDetailsActivity"));
                intent.PutExtra("package_name", PackageName);

                StartActivity(intent);

            }
            catch (Exception anfe)
            {
            }
        }

How to get into settings on other devices How to start Power Manager of all android manufactures to enable background and push notification?

Only I just don't understand how to find out the status of the flag