public class NetworkUsageManager
Parameter | Details |
---|---|
context: Context | Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. |
subscriberId: String? | In TelephonyManager has getSubscriberId() Returns the unique subscriber ID, for example, the IMSI for a GSM phone. |
To initialize NetworkUsageManager
you need to create and object and pass as a parameter Context
and TelephonyManager.getSubscriberId()
by default we provide an utility function
to getSubscriberId()
. Util.getSubscriberId(this)
will return subscriber id if it available. So, this method can be return null
.
val networkUsage = NetworkUsageManager(this, Util.getSubscriberId(this))
Usages In | Details |
---|---|
open NetworkUsageManager | fun getUsageNow(networkType: NetworkType: Usage return Usage of current Timestamp . It take NetworkType as a Parameter. |
open NetworkUsageManager | fun getUsage(interval: TimeInterval, networkType: NetworkType): Usage return Usage of a single Timestamp . It takes TimeInterval and NetworkType for get a single time prieod of Data. |
open NetworkUsageManager | fun getMultiUsage(intervals: List<TimeInterval>, networkType: NetworkType): List<DataUsage> return List of Usage of multiple Timestamp . It takes list of TimeInterval and NetworkType for get multi-time prieod of Data. |
object Interval
Name | Details |
---|---|
val today: TimeInterval |
This variable will return today start and end timeInMillis and today Date as TimeInterval format. |
val yesterday: TimeInterval |
This variable will return yesterday start and end timeInMillis and yesterday Date as TimeInterval format. |
val lastWeekDaily: List<TimeInterval> |
This variable will return start and end timeInMillis and Date of every day of last 7 days as list TimeInterval format. |
val lastMonthDaily: List<TimeInterval> |
This variable will return start and end timeInMillis and Date of every day of last 30 days as list TimeInterval format. |
val last7days: TimeInterval |
This variable will return last7days start and end timeInMillis and last7days Date as TimeInterval format. |
val last30days: TimeInterval |
This variable will return last7days start and end timeInMillis and last30days Date as TimeInterval format. |
val week: TimeInterval |
This variable will return a week of start and end timeInMillis and week Date as TimeInterval format. |
val month: TimeInterval |
This variable will return a month of start and end timeInMillis and month Date as TimeInterval format. |
Name | Details |
---|---|
fun monthlyPlan(startDay: Int): TimeInterval |
This method take startDay: Int as a parameter and return start and end timeInMillis and Date from startDay as TimeInterval format. |
fun weeklyPlan(startDay: Int): TimeInterval |
This method take startDay: Int as a parameter and return start and end timeInMillis and Date from startDay as TimeInterval format. |
data class Speed
This data class
has two variables
speed: String
for internet speed as stringunit: String
for speed unit (bits
/bytes
)
object NetSpeed
Name | Details |
---|---|
fun setSpeedUnitBits(isSpeedUnitBits: Boolean) |
This method take isSpeedUnitBits: Boolean as a parameter for set speed unit bits or bytes. |
fun getSpeedUnitBits(): Boolean |
This method return internet speed unit (bits /bytes ) |
fun calculateSpeed(timeTaken: Long, downBytes: Long, upBytes: Long): List<Speed> |
This method take time interval in milliseconds , download bytes and upload bytes and return type cast to human readable List of Speed format. |
enum class NetworkType
This enum class
has three type:
MOBILE
WIFI
ALL
data class TimeInterval(val start: Long, val end: Long,var date: String = "")
This data class
has three variables:
start: Long
: for interval starttimeInMillis
.end: Long
: for interval endtimeInMillis
.date: String = ""
: for date of interval.
data class Usage
This data class
has three variables:
downloads: Long = 0L
uploads: Long = 0L
timeTaken: Long = 0L
data class DataUsage
This data class
has three variables:
downloads: Long = 0L
uploads: Long = 0L
date: String = ""
object Util
Name | Details |
---|---|
fun getSubscriberId(context: Context): String? |
This method take Context as a parameter and return TelephonyManager.subscriberId and It can be nullable . |
fun formatData(sent: Long, received: Long): List<String> |
This method take upload and download bytes as Long and return listOf(sentData, receivedData, totalData) . |