ContextWrapper.GetSystemService(String) Method

Definition

Return the handle to a system-level service by name.

[Android.Runtime.Register("getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;", "GetGetSystemService_Ljava_lang_String_Handler")]
public override Java.Lang.Object? GetSystemService(string? name);
[<Android.Runtime.Register("getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;", "GetGetSystemService_Ljava_lang_String_Handler")>]
override this.GetSystemService : string -> Java.Lang.Object

Parameters

name
String

The name of the desired service.

Returns

Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are: WINDOW_SERVICE ("window") The top-level window manager in which you can place custom windows. The returned object is a WindowManager . Must only be obtained from a visual context such as Activity or a Context created with createWindowContext(int,Bundle) , which are adjusted to the configuration and visual bounds of an area on screen. LAYOUT_INFLATER_SERVICE ("layout_inflater") A LayoutInflater for inflating layout resources in this context. Must only be obtained from a visual context such as Activity or a Context created with createWindowContext(int,Bundle) , which are adjusted to the configuration and visual bounds of an area on screen. ACTIVITY_SERVICE ("activity") A ActivityManager for interacting with the global activity state of the system. WALLPAPER_SERVICE ("wallpaper") A WallpaperService for accessing wallpapers in this context. Must only be obtained from a visual context such as Activity or a Context created with createWindowContext(int,Bundle) , which are adjusted to the configuration and visual bounds of an area on screen. POWER_SERVICE ("power") A PowerManager for controlling power management. ALARM_SERVICE ("alarm") A AlarmManager for receiving intents at the time of your choosing. NOTIFICATION_SERVICE ("notification") A NotificationManager for informing the user of background events. KEYGUARD_SERVICE ("keyguard") A KeyguardManager for controlling keyguard. LOCATION_SERVICE ("location") A LocationManager for controlling location (e.g., GPS) updates. SEARCH_SERVICE ("search") A SearchManager for handling search. VIBRATOR_MANAGER_SERVICE ("vibrator_manager") A VibratorManager for accessing the device vibrators, interacting with individual ones and playing synchronized effects on multiple vibrators. ERROR(/#MULTISENSORY_MANAGER_SERVICE) ("multisensory_manager") A ERROR(/android.os.multisensory.MultisensoryManager) for delivering audio-haptic feedback in the Multisensory Design System VIBRATOR_SERVICE ("vibrator") A Vibrator for interacting with the vibrator hardware. CONNECTIVITY_SERVICE ("connectivity") A ConnectivityManager for handling management of network connections. IPSEC_SERVICE ("ipsec") A IpSecManager for managing IPSec on sockets and networks. WIFI_SERVICE ("wifi") A WifiManager for management of Wi-Fi connectivity. On releases before Android 7, it should only be obtained from an application context, and not from any other derived context to avoid memory leaks within the calling process. WIFI_AWARE_SERVICE ("wifiaware") A WifiAwareManager for management of Wi-Fi Aware discovery and connectivity. WIFI_P2P_SERVICE ("wifip2p") A WifiP2pManager for management of Wi-Fi Direct connectivity. INPUT_METHOD_SERVICE ("input_method") An InputMethodManager for management of input methods. UI_MODE_SERVICE ("uimode") An UiModeManager for controlling UI modes. DOWNLOAD_SERVICE ("download") A DownloadManager for requesting HTTP downloads BATTERY_SERVICE ("batterymanager") A BatteryManager for managing battery state JOB_SCHEDULER_SERVICE ("taskmanager") A JobScheduler for managing scheduled tasks NETWORK_STATS_SERVICE ("netstats") A NetworkStatsManager for querying network usage statistics. HARDWARE_PROPERTIES_SERVICE ("hardware_properties") A HardwarePropertiesManager for accessing hardware properties. DOMAIN_VERIFICATION_SERVICE ("domain_verification") A DomainVerificationManager for accessing web domain approval state. DISPLAY_HASH_SERVICE ("display_hash") A DisplayHashManager for management of display hashes. ERROR(/#AUTHENTICATION_POLICY_SERVICE) ("authentication_policy") A AuthenticationPolicyManager for managing authentication related policies on the device. Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.) Note: Instant apps, for which PackageManager.isInstantApp() returns true, don't have access to the following system services: DEVICE_POLICY_SERVICE , ERROR(/#FINGERPRINT_SERVICE) , KEYGUARD_SERVICE , SHORTCUT_SERVICE , USB_SERVICE , WALLPAPER_SERVICE , WIFI_P2P_SERVICE , WIFI_SERVICE , WIFI_AWARE_SERVICE . For these services this method will return null . Generally, if you are running as an instant app you should always check whether the result of this method is null . Note: When implementing this method, keep in mind that new services can be added on newer Android releases, so if you're looking for just the explicit names mentioned above, make sure to return null when you don't recognize the name — if you throw a RuntimeException exception instead, your app might break on new Android releases. Parameters name String : The name of the desired service. Value is one of the following: Context.POWER_SERVICE Context.WINDOW_SERVICE Context.LAYOUT_INFLATER_SERVICE Context.ACCOUNT_SERVICE Context.ACTIVITY_SERVICE Context.ALARM_SERVICE Context.NOTIFICATION_SERVICE Context.ACCESSIBILITY_SERVICE Context.CAPTIONING_SERVICE Context.KEYGUARD_SERVICE Context.LOCATION_SERVICE Context.HEALTHCONNECT_SERVICE Context.SEARCH_SERVICE Context.SENSOR_SERVICE Context.STORAGE_SERVICE Context.STORAGE_STATS_SERVICE Context.WALLPAPER_SERVICE Context.VIBRATOR_MANAGER_SERVICE Context.VIBRATOR_SERVICE Context.CONNECTIVITY_SERVICE Context.TETHERING_SERVICE Context.IPSEC_SERVICE Context.VPN_MANAGEMENT_SERVICE Context.NETWORK_STATS_SERVICE Context.WIFI_SERVICE Context.WIFI_AWARE_SERVICE Context.WIFI_P2P_SERVICE Context.WIFI_RTT_RANGING_SERVICE Context.NSD_SERVICE Context.AUDIO_SERVICE Context.BIOMETRIC_SERVICE Context.MEDIA_ROUTER_SERVICE Context.TELEPHONY_SERVICE Context.TELEPHONY_SUBSCRIPTION_SERVICE Context.TELEPHONY_PHONE_NUMBER_SERVICE Context.CARRIER_CONFIG_SERVICE Context.EUICC_SERVICE Context.TELECOM_SERVICE Context.CLIPBOARD_SERVICE Context.INPUT_METHOD_SERVICE Context.TEXT_SERVICES_MANAGER_SERVICE Context.TEXT_CLASSIFICATION_SERVICE Context.APPWIDGET_SERVICE Context.DROPBOX_SERVICE Context.DEVICE_POLICY_SERVICE Context.UI_MODE_SERVICE Context.DOWNLOAD_SERVICE Context.NFC_SERVICE Context.BLUETOOTH_SERVICE Context.USB_SERVICE Context.LAUNCHER_APPS_SERVICE Context.SERIAL_SERVICE Context.INPUT_SERVICE Context.DISPLAY_SERVICE Context.USER_SERVICE Context.RESTRICTIONS_SERVICE Context.APP_OPS_SERVICE Context.ROLE_SERVICE Context.CAMERA_SERVICE Context.PRINT_SERVICE Context.CONSUMER_IR_SERVICE Context.TV_INTERACTIVE_APP_SERVICE Context.TV_INPUT_SERVICE Context.USAGE_STATS_SERVICE Context.MEDIA_SESSION_SERVICE Context.MEDIA_COMMUNICATION_SERVICE Context.BATTERY_SERVICE Context.JOB_SCHEDULER_SERVICE Context.PERSISTENT_DATA_BLOCK_SERVICE Context.MEDIA_PROJECTION_SERVICE Context.MIDI_SERVICE Context.HARDWARE_PROPERTIES_SERVICE Context.SHORTCUT_SERVICE Context.SYSTEM_HEALTH_SERVICE Context.COMPANION_DEVICE_SERVICE Context.VIRTUAL_DEVICE_SERVICE Context.CROSS_PROFILE_APPS_SERVICE Context.LOCALE_SERVICE Context.MEDIA_METRICS_SERVICE Context.DISPLAY_HASH_SERVICE Context.CREDENTIAL_SERVICE Context.DEVICE_LOCK_SERVICE Context.GRAMMATICAL_INFLECTION_SERVICE Context.SECURITY_STATE_SERVICE Context.CONTACT_KEYS_SERVICE Context.MEDIA_QUALITY_SERVICE Context.ADVANCED_PROTECTION_SERVICE Context.NPU_SERVICE Context.WEB_APP_SERVICE Context.HID_SERVICE . This value cannot be null . Returns Object The service or null if the name does not exist.

Attributes

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Java documentation for android.content.ContextWrapper.getSystemService(java.lang.String).

Applies to