Last active
November 14, 2019 07:12
-
-
Save shmehdi01/c80686ddf4140062800839538aa5aafb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Utils { | |
fun loadJSONFromAsset(filePath: String): String? { | |
var json: String? = null | |
try { | |
val `is` = Objects.requireNonNull<MyApp>(MyApp.instance).assets.open(filePath) | |
val size = `is`.available() | |
val buffer = ByteArray(size) | |
`is`.read(buffer) | |
`is`.close() | |
json = String(buffer, charset("UTF-8")) | |
} catch (ex: IOException) { | |
ex.printStackTrace() | |
return null | |
} | |
return json | |
} | |
fun isMyServiceRunning(serviceClass: Class<*>): Boolean { | |
val manager = MyApp.instance?.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager? | |
for (service in manager!!.getRunningServices(Integer.MAX_VALUE)) { | |
if (serviceClass.name == service.service.className) { | |
return true | |
} | |
} | |
return false | |
} | |
fun getCommaSepratedId(names: List<String>): String { | |
if(names.isNullOrEmpty()) { | |
return "" | |
} | |
var namesStr = StringBuilder() | |
for (name in names) { | |
namesStr = | |
if (namesStr.isNotEmpty()) namesStr.append(",").append(name) else namesStr.append(name) | |
} | |
return namesStr.toString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment