platypush-app/app/src/main/java/tech/platypush/app/WebAppInterface.kt

33 lines
760 B
Kotlin

package tech.platypush.app
import android.content.Context
import android.webkit.JavascriptInterface
import org.json.JSONArray
import java.util.*
class WebAppInterface(context: Context) {
private val serviceScanner = Scanner(context)
@Suppress("unused")
@JavascriptInterface
fun startServicesPoll() {
serviceScanner.startScan()
}
@Suppress("unused")
@JavascriptInterface
fun stopServicesPoll() {
serviceScanner.stopScan()
}
@Suppress("unused")
@JavascriptInterface
fun pollServices(): String {
val services = LinkedList<Map<String, Any?>>()
for (srv in serviceScanner.getServices())
services.add(srv.toMap())
return JSONArray(services).toString()
}
}