【问题标题】:Integrating Braintree dropin UI into Kotlin Jetpack Compose将 Braintree dropin UI 集成到 Kotlin Jetpack Compose
【发布时间】:2021-08-06 04:19:19
【问题描述】:

我正在尝试将https://developer.paypal.com/braintree/docs/guides/drop-in/setup-and-integration#starting-drop-in 此处的 android/java dropin UI 代码转换为 jetpack compose 应用程序。到目前为止我有

@Composable
fun Account(user: FinUser) {
    val context = LocalContext.current
    val customerToken = user.userData["customerToken"] as String
    val dropInRequest = DropInRequest()
        .clientToken(customerToken)
    val dropInHintLauncher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.StartIntentSenderForResult()
    ) {
        print("pause here")
    }
    val dropInIntent = dropInRequest.getIntent(context)
    val dropInPendingIntent = PendingIntent.getBroadcast(
        context, 200, dropInIntent,
        PendingIntent.FLAG_UPDATE_CURRENT
    )
    Column(){
        Column(
            Modifier
                .padding(top = 0.dp)
                .clickable { launchDropInUi(
                    dropInHintLauncher=dropInHintLauncher,
                    dropInPendingIntent=dropInPendingIntent) }) {
            Divider(color = Color.LightGray, thickness = 1.dp)
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(20.dp, 10.dp)
            ) {
                Column() {
                    Text("Payment", color = Color.Gray)
                    Text("*********9999", color = Color.Black)
                }
                Spacer(modifier = Modifier.fillMaxWidth())
            }
            Divider(color = Color.LightGray, thickness = 1.dp)
        }
    }
}

fun launchDropInUi(dropInHintLauncher: ManagedActivityResultLauncher<IntentSenderRequest, ActivityResult>, dropInPendingIntent: PendingIntent){
    dropInHintLauncher.launch(
        IntentSenderRequest.Builder(dropInPendingIntent).build()
    )
}

当我点击我的行时,没有 dropin UI 弹出窗口,但它确实注册了点击并在 launchDropInUi 函数上运行。

【问题讨论】:

    标签: kotlin braintree android-jetpack-compose


    【解决方案1】:

    我发现了问题。我需要使用

        val dropInHintLauncher = rememberLauncherForActivityResult(
            contract = ActivityResultContracts.StartActivityForResult()
        )
    

    给予

    @Composable
    fun Account(user: FinUser) {
        val context = LocalContext.current
        val customerToken = user.userData["customerToken"] as String
        val dropInRequest = DropInRequest()
            .clientToken(customerToken)
        val dropInHintLauncher = rememberLauncherForActivityResult(
            contract = ActivityResultContracts.StartActivityForResult()
        ){ result: ActivityResult ->
            if (result.resultCode == Activity.RESULT_OK) {
                //  you will get result here in result.data
                val data: DropInResult? = result.data?.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT)
            }else{
                print("throw error popup")
            }
        }
        val dropInIntent = dropInRequest.getIntent(context)
        Column(){
            Column(
                Modifier
                    .padding(top = 0.dp)
                    .clickable { launchDropInUi(
                        dropInHintLauncher =dropInHintLauncher,
                        dropInIntent =dropInIntent) }) {
                Divider(color = Color.LightGray, thickness = 1.dp)
                Row(
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(20.dp, 10.dp)
                ) {
                    Column() {
                        Text("Payment", color = Color.Gray)
                        Text("*********9999", color = Color.Black)
                    }
                    Spacer(modifier = Modifier.fillMaxWidth())
                }
                Divider(color = Color.LightGray, thickness = 1.dp)
            }
        }
    }
    fun launchDropInUi(dropInHintLauncher: ManagedActivityResultLauncher<Intent, ActivityResult>, dropInIntent: Intent){
        dropInHintLauncher.launch(dropInIntent)
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-05
      • 1970-01-01
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2015-03-11
      • 2015-01-14
      • 2015-10-14
      相关资源
      最近更新 更多