mihon/app/src/main/java/eu/kanade/tachiyomi/util/DeviceUtil.kt
NoodleMage 55e9d2880c Rewrote UpdateDownloader to Kotlin
Added auto update check (every 12 hour)
Warning message optional fix #256
Lots of bug fixes!
2016-04-26 20:57:05 +02:00

24 lines
No EOL
962 B
Kotlin

package eu.kanade.tachiyomi.util
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.ConnectivityManager
import android.os.BatteryManager
object DeviceUtil {
fun isPowerConnected(context: Context): Boolean {
val intent = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
intent?.let {
val plugged = it.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS
}
return false
}
fun isNetworkConnected(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetworkInfo
return activeNetwork != null && activeNetwork.isConnectedOrConnecting
}
}