/// <summary> /// 无障碍服务是否启动。 /// </summary> /// <returns></returns> public bool IsAccessibilityServiceEnabled() { var expectedComponentName = new ComponentName(Context, Class.FromType(typeof(AutoAccessibilityService))); var enabledServicesSetting = Android.Provider.Settings.Secure.GetString(Context.ContentResolver, Android.Provider.Settings.Secure.EnabledAccessibilityServices); if (enabledServicesSetting == null) { return(false); } var colonSplitter = new TextUtils.SimpleStringSplitter(':'); colonSplitter.SetString(enabledServicesSetting); while (colonSplitter.HasNext) { var componentNameString = colonSplitter.Next(); var enabledService = ComponentName.UnflattenFromString(componentNameString); if (enabledService != null && enabledService == expectedComponentName) { return(true); } } return(false); }
private void RefreshIsAssistant() { string assistant = Settings.Secure.GetString(ContentResolver, "voice_interaction_service"); isAssistant = false; if (assistant != null) { ComponentName componentName = ComponentName.UnflattenFromString(assistant); if (componentName != null && componentName.PackageName == PackageName) { isAssistant = true; } } }
public static void NotifyCalendarEventsUpdated() { try { var manager = AppWidgetManager.GetInstance(Application.Context); int[] appWidgetID1s = manager.GetAppWidgetIds(new ComponentName(Application.Context, "me.ichrono.droid.Widgets.Calendar.CalendarWidget")); Intent updateIntent = new Intent(AppWidgetManager.ActionAppwidgetUpdate); updateIntent.SetComponent(ComponentName.UnflattenFromString("me.ichrono.droid/me.ichrono.droid.Widgets.Calendar.CalendarWidget")); AppWidgetManager widgetManager = AppWidgetManager.GetInstance(Application.Context); updateIntent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetID1s); Application.Context.SendBroadcast(updateIntent); } catch (Exception ex) { ex.ToString(); } }
public Task OpenWifiSettings() { Intent intent = new Intent("android.intent.action.MAIN"); intent.SetComponent(ComponentName.UnflattenFromString("com.android.settings/.wifi.WifiSettings")); intent.AddCategory("android.intent.category.DEFAULT"); return(Task.Run(() => { try { CurrentContext.StartActivity(intent); } catch (Exception) { Toast.MakeText(CurrentContext.ApplicationContext, "Unable to open Wifi Settings", ToastLength.Short); } })); }
private void LoadAllFolders() { MFolders = new SparseArray <FolderModel>(); string[] folders = FileList(); foreach (string folderFileName in folders) { System.IO.FileStream @in = null; try { if (folderFileName.StartsWith("folder", StringComparison.Ordinal)) { FolderModel folder = new FolderModel(); folder.Id = int.Parse(folderFileName.Substring("folder".Length)); @in = (System.IO.FileStream)OpenFileInput(folderFileName); System.IO.MemoryStream bos = new System.IO.MemoryStream(); byte[] b = new byte[1024]; int bytesRead; while ((bytesRead = @in.Read(b, 0, b.Length)) != -1) { bos.Write(b, 0, bytesRead); } byte[] bytes = bos.ToArray(); string appNames = StringHelperClass.NewString((sbyte[])(Array)bytes); int i = 0; foreach (string appName in appNames.Split("\n", true)) { if (i < 2) { // width and height try { if (i == 0) { folder.Width = int.Parse(appName); } else if (i == 1) { folder.Height = int.Parse(appName); } } catch (System.FormatException) { string msg = "Please uninstall Floating Folders and reinstall it. The folder format has changed."; Log.Debug("FloatingFolder", msg); Toast.MakeText(this, msg, ToastLength.Short).Show(); break; } i++; } else { if (appName.Length > 0) { ComponentName name = ComponentName.UnflattenFromString(appName); try { ActivityInfo app = MPackageManager.GetActivityInfo(name, 0); folder.Apps.Add(app); MFolders.Put(folder.Id, folder); } catch (PackageManager.NameNotFoundException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } } } } } } catch (FileNotFoundException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } catch (IOException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } finally { if (@in != null) { try { @in.Close(); } catch (IOException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } } } } }