如何在Android Studio中使用Kotlin,当点击CardView时重定向到应用程序?

huangapple go评论59阅读模式
英文:

How to redirect to application, When CardView was Clicked using kotlin in android studio?

问题

@Composable
fun mycard(
    data: MyModel,
) {

    var value = Card(
        elevation = 14.dp,
        shape = RoundedCornerShape(20.dp),
        modifier = Modifier
            .padding(horizontal = 12.dp)
            .width(350.dp)
            .height(190.dp)
            .background(Color.Transparent)
            .clickable {
                val launchIntent =
                    packageManager.getLaunchIntentForPackage("com.google.android.youtube.tv")
                launchIntent?.let { startActivity(it) }
            }
    )
英文:
@Composable
fun mycard(
	data: MyModel,
) {

	var value = Card(
		elevation = 14.dp,
		shape = RoundedCornerShape(20.dp),
		modifier = Modifier

			.padding(horizontal = 12.dp)
			.width(350.dp)
			.height(190.dp)
			.background(Color.Transparent)
			.clickable {
				val launchIntent =
					packageManager.getLaunchIntentForPackage("com.google.android.youtube.tv")
				launchIntent?.let { startActivity(it) }
			}

I have added the card and the card was clickable but not redirect to specific application please solve my doubt

答案1

得分: 2

使用此脚本:

apps.setOnClickListener {
    val packageName = "com.google.android.youtube.tv"
    val intent = packageManager.getLaunchIntentForPackage(packageName)
    if (intent != null) startActivity(intent)
    else
        Toast.makeText(this, "该应用未安装!", Toast.LENGTH_SHORT).show()
}
英文:

Use this Script ;

   apps.setOnClickListener {
                val packageName = "com.google.android.youtube.tv" 
                val intent = packageManager.getLaunchIntentForPackage(packageName)
                if (intent != null) startActivity(intent)
                else
                    Toast.makeText(this, "The Application is not installed!", Toast.LENGTH_SHORT).show()
            }

huangapple
  • 本文由 发表于 2023年3月7日 13:43:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定