Firebase Cloud Messaging(FCM)のHTTP legacy protocolでsendするメモ
fcm_regacy_http.kt
import okhttp3.* private const val URL = "https://fcm.googleapis.com/fcm/send" private val MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8") private val CLIENT = OkHttpClient() fun send(serverKey: String, jsonString: String): Response = newCall(serverKey, jsonString).execute() fun send(serverKey: String, jsonString: String, callback: Callback) { newCall(serverKey, jsonString).enqueue(callback) } private fun newCall(serverKey: String, jsonString: String): Call = CLIENT.newCall(Request.Builder() .url(URL) .header("Authorization", "key=$serverKey") .post(RequestBody.create(MEDIA_TYPE_JSON, jsonString)) .build() )