...
class MainActivity : FlutterFragmentActivity(), MethodCallHandler {
private lateinit var channel: MethodChannel
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
checkPayload(intent.extras)
}
// 푸시 수신 데이터 체크
private fun checkPayload(data: Bundle?) {
if (data != null) {
val jsonObject = JSONObject()
val payload = data.getBundle("payload")
val keys = payload?.keySet()
if (keys != null) {
for (key in keys) {
jsonObject.put(key, payload?.getString(key))
}
sendPayload(jsonObject.toString())
}
}
}
private fun sendPayload(payload: String) {
if (this::channel.isInitialized) {
channel.invokeMethod("onNotification", payload)
} else {
Handler(mainLooper).postDelayed({ sendPayload(payload) }, 200)
}
}
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
GeneratedPluginRegistrant.registerWith(flutterEngine)
channel = MethodChannel(flutterEngine.dartExecutor, "FingerPushOnNotification")
channel.setMethodCallHandler(this@MainActivity)
if (intent.extras != null) {
checkPayload(intent.extras)
}
}
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
if (call.method.equals("onNotification")) {
checkPayload(intent.extras)
}
}
}