import android.os.Bundle
import org.json.JSONObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/**
* Extension function to convert a Bundle to a JSONObject.
*/
fun Bundle?.toJsonObject(): JSONObject {
val jsonObject = JSONObject()
this?.let {
for (key in it.keySet()) {
val value = it.get(key)
jsonObject.put(key, value)
}
}
return jsonObject
}
// Usage within a CoroutineScope. You usually want to put this inside you onCreate function.
CoroutineScope(Dispatchers.Main).launch {
if (intent?.extras?.getString("sender") == "GLEAP") {
Gleap.getInstance().handlePushNotification(intent.extras.toJsonObject())
}
}