Skip to content

Instantly share code, notes, and snippets.

@akshaykalola28
Created April 5, 2023 09:29
Show Gist options
  • Save akshaykalola28/2bc366a8a04cd4f291b40a10cd1c8642 to your computer and use it in GitHub Desktop.
Save akshaykalola28/2bc366a8a04cd4f291b40a10cd1c8642 to your computer and use it in GitHub Desktop.
Extension function to access system service manager in android
import android.app.DownloadManager
import android.app.NotificationManager
import android.content.Context
import android.net.ConnectivityManager
import android.view.WindowManager
import androidx.core.content.ContextCompat
val Context.windowManager
get() = ContextCompat.getSystemService(this, WindowManager::class.java)
val Context.connectivityManager
get() = ContextCompat.getSystemService(this, ConnectivityManager::class.java)
val Context.notificationManager
get() = ContextCompat.getSystemService(this, NotificationManager::class.java)
val Context.downloadManager
get() = ContextCompat.getSystemService(this, DownloadManager::class.java)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment