如何在 AWS pinpoint 中创建一个可以由 Android Kotlin 中的 OnClick 事件触发的事件

How to create an event in AWS pinpoint which can be triggered by OnClick event in Android Kotlin

当我尝试在 AWS Pinpoint 中创建一个将在 OnClickListerner 上触发的事件时,我正尝试在我的项目中实施 AWS Pinpoint 以进行移动分析。以下是代码片段。每当我尝试在 OnClickListener 中创建事件时,无法识别该特定事件,请帮助我了解如何完成。

inviteButton.setOnClickListener {
                    val tinyDb = TinyDB(App.ctx)

                    val userDetails = tinyDb.getCurrentUserCachedDetails()
                    val userAttributesMap = userDetails.attributes.attributes
                    val username =
                            userAttributesMap[SettingsFragment.KEY_FIRST_NAME] + " " + userAttributesMap[SettingsFragment.KEY_LAST_NAME]
                    val project = ProjectRepository(ProjectDao()).getProjectById(projectCode)
                    val bitmap =
                            BitmapFactory.decodeResource(resources, R.drawable.project_invite)
                    val mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true)
                    val canvas = Canvas(mutableBitmap)
                    val scale = resources.displayMetrics.density
                    val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
                        color = Color.BLACK
                        textSize = 100 * scale
                    }
                    canvas.drawText(
                            projectCode.toString(),
                            400.toFloat() * scale,
                            440.toFloat() * scale,
                            paint
                    )

                    val originalFile = File(App.ctx.externalMediaDirs[0], "project_invite.png")
                    originalFile.createNewFile()
                    val originalFileBos = ByteArrayOutputStream()
                    mutableBitmap.compress(Bitmap.CompressFormat.PNG, 0, originalFileBos)
                    val originalFileByteArray = originalFileBos.toByteArray()
                    val originalFileFos = FileOutputStream(originalFile)
                    originalFileFos.write(originalFileByteArray)
                    originalFileFos.flush()
                    originalFileFos.close()

                    val defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(App.ctx)

                    val intent = Intent(Intent.ACTION_SEND)
                    intent.putExtra(
                            Intent.EXTRA_STREAM,
                            FileProvider.getUriForFile(
                                    App.ctx,
                                    "${App.ctx.packageName}.fileprovider",
                                    originalFile
                            )
                    )
                    intent.putExtra(Intent.EXTRA_TEXT, message)
                    intent.putExtra("sms_body", message)
                    intent.type = "image/png"
                    defaultSmsApp?.let {
                        intent.`package` = it
                        try {
                            activity?.startActivity(intent)
                        } catch (e: ActivityNotFoundException) {
                            e { e }
                            toastError("Unable to open SMS app.")
                        }
                    } ?: toastError("No default SMS app found.")


                    val Email = tinyDb.getString(getString(R.string.logged_in_user))
                    val event = AnalyticsEvent.builder()
                            .name("invites")
                            .addProperty("email", Email)
                            .build()

                    log { "Invite event"+ event }
                    Amplify.Analytics.recordEvent(event)
                    log { "Invite here 11"+ Amplify.Analytics.recordEvent(event) }

                }
inviteButton.setOnClickListener {
                    val tinyDb = TinyDB(App.ctx)

                    val userDetails = tinyDb.getCurrentUserCachedDetails()
                    val userAttributesMap = userDetails.attributes.attributes
                    val username =
                            userAttributesMap[SettingsFragment.KEY_FIRST_NAME] + " " + userAttributesMap[SettingsFragment.KEY_LAST_NAME]

 val Email = tinyDb.getString(getString(R.string.logged_in_user))
                    val event = AnalyticsEvent.builder()
                            .name("invites")
                            .addProperty("email", Email)
                            .build()

                    log { "Invite event"+ event }
                    Amplify.Analytics.recordEvent(event)
                    log { "Invite here 11"+ Amplify.Analytics.recordEvent(event) }
                    val project = ProjectRepository(ProjectDao()).getProjectById(projectCode)
                    val bitmap =
                            BitmapFactory.decodeResource(resources, R.drawable.project_invite)
                    val mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true)
                    val canvas = Canvas(mutableBitmap)
                    val scale = resources.displayMetrics.density
                    val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
                        color = Color.BLACK
                        textSize = 100 * scale
                    }
                    canvas.drawText(
                            projectCode.toString(),
                            400.toFloat() * scale,
                            440.toFloat() * scale,
                            paint
                    )

                    val originalFile = File(App.ctx.externalMediaDirs[0], "project_invite.png")
                    originalFile.createNewFile()
                    val originalFileBos = ByteArrayOutputStream()
                    mutableBitmap.compress(Bitmap.CompressFormat.PNG, 0, originalFileBos)
                    val originalFileByteArray = originalFileBos.toByteArray()
                    val originalFileFos = FileOutputStream(originalFile)
                    originalFileFos.write(originalFileByteArray)
                    originalFileFos.flush()
                    originalFileFos.close()

                    val defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(App.ctx)

                    val intent = Intent(Intent.ACTION_SEND)
                    intent.putExtra(
                            Intent.EXTRA_STREAM,
                            FileProvider.getUriForFile(
                                    App.ctx,
                                    "${App.ctx.packageName}.fileprovider",
                                    originalFile
                            )
                    )
                    intent.putExtra(Intent.EXTRA_TEXT, message)
                    intent.putExtra("sms_body", message)
                    intent.type = "image/png"
                    defaultSmsApp?.let {
                        intent.`package` = it
                        try {
                            activity?.startActivity(intent)
                        } catch (e: ActivityNotFoundException) {
                            e { e }
                            toastError("Unable to open SMS app.")
                        }
                    } ?: toastError("No default SMS app found.")
                }