-
Notifications
You must be signed in to change notification settings - Fork 5
ContextExtensions
Birju Vachhani edited this page Sep 26, 2019
·
3 revisions
val inputManager = getService<InputMethodManager>(Context.INPUT_METHOD_SERVICE)All the casting is done implicitly for you in a safe way. Returns the service or null if the name does not exist.
If your app's minSDK is 23, then you can use this:
val activityManager: ActivityManager? = context.getServiceOrNull() // returns service instance or null
val notificationManger: NotificationManager = context.getService() // returns non-null service instance, throws exception if not foundapplication<MyApp>()If you'll not behave then you'll get an exception thrown right into your face. (ClassCastException)
hasInternet() // returns BooleanlayoutInflater // yes, it's a property!This extension can be used to know which type of internet connectivity is being used.
Possible types are Not Connected, WIFI, 2G, 3G, 4G and 5G.
context.getQualityOfService() // requires Android Lollipop or higherFor more information, look at the ContextExtensions.kt file.
Here are the available Class Extensions: