2016-04-13 08:08:07 -04:00
|
|
|
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)
|
2016-04-17 18:20:58 -04:00
|
|
|
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS
|
2016-04-13 08:08:07 -04:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|