Android getSystemService

本文详细介绍了Android系统中可通过Context获取的各种服务,如ActivityManager、AudioManager等,并提供了getSystemService方法的具体实现,帮助开发者更好地理解如何在应用中使用这些服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在android中有一些服务是得通过系统来得的,下面一整个的SystemService ,

在android的官方文档中大家 可以到

Context这个类下去找,

 

 

Summary

Constants
StringACCESSIBILITY_SERVICEUse with getSystemService(String) to retrieve a AccessibilityManager for giving the user feedback for UI events through the registered event listeners.
StringACCOUNT_SERVICEUse with getSystemService(String) to retrieve a AccountManager for receiving intents at a time of your choosing.
StringACTIVITY_SERVICEUse with getSystemService(String) to retrieve a ActivityManager for interacting with the global system state.
StringALARM_SERVICEUse with getSystemService(String) to retrieve a AlarmManager for receiving intents at a time of your choosing.
StringAUDIO_SERVICEUse with getSystemService(String) to retrieve a AudioManager for handling management of volume, ringer modes and audio routing.
intBIND_ABOVE_CLIENTFlag for bindService(Intent, ServiceConnection, int): indicates that the client application binding to this service considers the service to be more important than the app itself.
intBIND_ADJUST_WITH_ACTIVITYFlag for bindService(Intent, ServiceConnection, int): If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user, regardless whether another flag is used to reduce the amount that the client process's overall importance is used to impact it.
intBIND_ALLOW_OOM_MANAGEMENTFlag for bindService(Intent, ServiceConnection, int): allow the process hosting the bound service to go through its normal memory management.
intBIND_AUTO_CREATEFlag for bindService(Intent, ServiceConnection, int): automatically create the service as long as the binding exists.
intBIND_DEBUG_UNBINDFlag for bindService(Intent, ServiceConnection, int): include debugging help for mismatched calls to unbind.
intBIND_IMPORTANTFlag for bindService(Intent, ServiceConnection, int): this service is very important to the client, so should be brought to the foreground process level when the client is.
intBIND_NOT_FOREGROUNDFlag for bindService(Intent, ServiceConnection, int): don't allow this binding to raise the target service's process to the foreground scheduling priority.
intBIND_WAIVE_PRIORITYFlag for bindService(Intent, ServiceConnection, int): don't impact the scheduling or memory management priority of the target service's hosting process.
StringCLIPBOARD_SERVICEUse with getSystemService(String) to retrieve a ClipboardManager for accessing and modifying the contents of the global clipboard.
StringCONNECTIVITY_SERVICEUse with getSystemService(String) to retrieve a ConnectivityManager for handling management of network connections.
intCONTEXT_IGNORE_SECURITYFlag for use with createPackageContext(String, int): ignore any security restrictions on the Context being requested, allowing it to always be loaded.
intCONTEXT_INCLUDE_CODEFlag for use with createPackageContext(String, int): include the application code with the context.
intCONTEXT_RESTRICTEDFlag for use with createPackageContext(String, int): a restricted context may disable specific features.
StringDEVICE_POLICY_SERVICEUse with getSystemService(String) to retrieve a DevicePolicyManager for working with global device policy management.
StringDOWNLOAD_SERVICEUse with getSystemService(String) to retrieve a DownloadManager for requesting HTTP downloads.
StringDROPBOX_SERVICEUse with getSystemService(String) to retrieve a DropBoxManager instance for recording diagnostic logs.
StringINPUT_METHOD_SERVICEUse with getSystemService(String) to retrieve a InputMethodManager for accessing input methods.
StringKEYGUARD_SERVICEUse with getSystemService(String) to retrieve a NotificationManager for controlling keyguard.
StringLAYOUT_INFLATER_SERVICEUse with getSystemService(String) to retrieve a LayoutInflater for inflating layout resources in this context.
StringLOCATION_SERVICEUse with getSystemService(String) to retrieve a LocationManager for controlling location updates.
intMODE_APPENDFile creation mode: for use with openFileOutput(String, int), if the file already exists then write data to the end of the existing file instead of erasing it.
intMODE_MULTI_PROCESSSharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process.
intMODE_PRIVATEFile creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).
intMODE_WORLD_READABLEFile creation mode: allow all other applications to have read access to the created file.
intMODE_WORLD_WRITEABLEFile creation mode: allow all other applications to have write access to the created file.
StringNFC_SERVICEUse with getSystemService(String) to retrieve a NfcManager for using NFC.
StringNOTIFICATION_SERVICEUse with getSystemService(String) to retrieve a NotificationManager for informing the user of background events.
StringPOWER_SERVICEUse with getSystemService(String) to retrieve a PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.
StringSEARCH_SERVICEUse with getSystemService(String) to retrieve a SearchManager for handling searches.
StringSENSOR_SERVICEUse with getSystemService(String) to retrieve a SensorManager for accessing sensors.
StringSTORAGE_SERVICEUse with getSystemService(String) to retrieve a StorageManager for accessing system storage functions.
StringTELEPHONY_SERVICEUse with getSystemService(String) to retrieve a TelephonyManager for handling management the telephony features of the device.
StringTEXT_SERVICES_MANAGER_SERVICEUse with getSystemService(String) to retrieve a TextServicesManager for accessing text services.
StringUI_MODE_SERVICEUse with getSystemService(String) to retrieve a UiModeManager for controlling UI modes.
StringUSB_SERVICEUse with getSystemService(String) to retrieve a UsbManager for access to USB devices (as a USB host) and for controlling this device's behavior as a USB device.
StringVIBRATOR_SERVICEUse with getSystemService(String) to retrieve a Vibrator for interacting with the vibration hardware.
StringWALLPAPER_SERVICEUse with getSystemService(String) to retrieve a com.android.server.WallpaperService for accessing wallpapers.
StringWIFI_P2P_SERVICEUse with getSystemService(String) to retrieve a WifiP2pManager for handling management of Wi-Fi peer-to-peer connections.
StringWIFI_SERVICEUse with getSystemService(String) to retrieve a WifiManager for handling management of Wi-Fi access.
StringWINDOW_SERVICEUse with getSystemService(String) to retrieve a WindowManager for accessing the system's window manager.

 

 

 

  1.  public Object getSystemService(String name) {  
  2.         if (WINDOW_SERVICE.equals(name)) {  
  3.             return WindowManagerImpl.getDefault();  
  4.         } else if (LAYOUT_INFLATER_SERVICE.equals(name)) {  
  5.             synchronized (mSync) {  
  6.                 LayoutInflater inflater = mLayoutInflater;  
  7.                 if (inflater != null) {  
  8.                     return inflater;  
  9.                 }  
  10.                 mLayoutInflater = inflater =  
  11.                     PolicyManager.makeNewLayoutInflater(getOuterContext());  
  12.                 return inflater;  
  13.             }  
  14.         } else if (ACTIVITY_SERVICE.equals(name)) {  
  15.             return getActivityManager();  
  16.         } else if (INPUT_METHOD_SERVICE.equals(name)) {  
  17.             return InputMethodManager.getInstance(this);  
  18.         } else if (ALARM_SERVICE.equals(name)) {  
  19.             return getAlarmManager();  
  20.         } else if (ACCOUNT_SERVICE.equals(name)) {  
  21.             return getAccountManager();  
  22.         } else if (POWER_SERVICE.equals(name)) {  
  23.             return getPowerManager();  
  24.         } else if (CONNECTIVITY_SERVICE.equals(name)) {  
  25.             return getConnectivityManager();  
  26.         } else if (THROTTLE_SERVICE.equals(name)) {  
  27.             return getThrottleManager();  
  28.         } else if (WIFI_SERVICE.equals(name)) {  
  29.             return getWifiManager();  
  30.         } else if (NOTIFICATION_SERVICE.equals(name)) {  
  31.             return getNotificationManager();  
  32.         } else if (KEYGUARD_SERVICE.equals(name)) {  
  33.             return new KeyguardManager();  
  34.         } else if (ACCESSIBILITY_SERVICE.equals(name)) {  
  35.             return AccessibilityManager.getInstance(this);  
  36.         } else if (LOCATION_SERVICE.equals(name)) {  
  37.             return getLocationManager();  
  38.         } else if (SEARCH_SERVICE.equals(name)) {  
  39.             return getSearchManager();  
  40.         } else if (SENSOR_SERVICE.equals(name)) {  
  41.             return getSensorManager();  
  42.         } else if (STORAGE_SERVICE.equals(name)) {  
  43.             return getStorageManager();  
  44.         } else if (VIBRATOR_SERVICE.equals(name)) {  
  45.             return getVibrator();  
  46.         } else if (STATUS_BAR_SERVICE.equals(name)) {  
  47.             synchronized (mSync) {  
  48.                 if (mStatusBarManager == null) {  
  49.                     mStatusBarManager = new StatusBarManager(getOuterContext());  
  50.                 }  
  51.                 return mStatusBarManager;  
  52.             }  
  53.         } else if (AUDIO_SERVICE.equals(name)) {  
  54.             return getAudioManager();  
  55.         } else if (TELEPHONY_SERVICE.equals(name)) {  
  56.             return getTelephonyManager();  
  57.         } else if (CLIPBOARD_SERVICE.equals(name)) {  
  58.             return getClipboardManager();  
  59.         } else if (WALLPAPER_SERVICE.equals(name)) {  
  60.             return getWallpaperManager();  
  61.         } else if (DROPBOX_SERVICE.equals(name)) {  
  62.             return getDropBoxManager();  
  63.         } else if (DEVICE_POLICY_SERVICE.equals(name)) {  
  64.             return getDevicePolicyManager();  
  65.         } else if (UI_MODE_SERVICE.equals(name)) {  
  66.             return getUiModeManager();  
  67.         }  
  68.   
  69.         return null;  
  70.     } 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值