Turn on Airplane mode using AccessibilityService Class in Xamarin

大城市里の小女人 提交于 2020-06-17 05:52:28

问题


I want to turn on or off airplane mode using AccessibilityService.

Any idea how we can do it?


回答1:


Kamal you’re not going to be able to do it.

It doesn’t seem like you’re doing iOS, but iOS has a lot of limitations due to privacy and security purposes that won’t allow you to do this. You can see more details here stackoverflow.com/q/20469425/11104068

Also android blocked being able to do this from Android 4.2 onwards. Only system apps can make changes to Airplane mode, as you can see here stackoverflow.com/a/5533943/11104068 Since it doesn’t seem you’re creating a system app that gets installed with the operating system, and not through the Play Store, you won’t be able to get permissions. It will give you an error /exception even if you implement everything




回答2:


Yes, you can't change it from app that target bigger than Android 4.2. But you can open the settings page instead if you want:

     if (Android.OS.Build.VERSION.SdkInt < BuildVersionCodes.JellyBeanMr1)
            {
                try
                {
                    Intent intentAirplaneMode = new Intent(Android.Provider.Settings.ActionAirplaneModeSettings);
                    intentAirplaneMode.SetFlags(ActivityFlags.NewTask);
                    Context.StartActivity(intentAirplaneMode);
                }
                catch (ActivityNotFoundException e)
                {
                    Log.Error("exception", e + "");
                }
            }
            else
            {
                Intent intent1 = new Intent("android.settings.WIRELESS_SETTINGS");
                intent1.SetFlags(ActivityFlags.NewTask); 
                Context.StartActivity(intent1);
            }
   }

And AccessibilityService can used with dependency service.



来源:https://stackoverflow.com/questions/61292189/turn-on-airplane-mode-using-accessibilityservice-class-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!