Skip to content

Instantly share code, notes, and snippets.

View VasylT's full-sized avatar
🐢
On the way to success

Vasyl Tkachov VasylT

🐢
On the way to success
  • Kyiv, Ukraine
View GitHub Profile
@VasylT
VasylT / NetworkUtils.kt
Created October 7, 2020 16:46
Check internet connection
object NetworkUtils {
fun isConnected(context: Context): Boolean {
return isConnected(context, false)
}
fun isConnected(context: Context, checkNetworkCapability: Boolean): Boolean {
var isOnline = false
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val nw = connectivityManager.activeNetwork ?: return false
@VasylT
VasylT / EnableLocation.kt
Last active October 9, 2020 19:05
Request enable location
class EnableLocation : AppCompatActivity() {
private fun isLocationEnabled() : Boolean {
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
return locationManager.isLocationEnabled
}
private fun showEnableLocationDialog() {
val locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)