我有这样的kotlin应用程序:
package com.test.openchrome
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val launcher = findViewById<Button>(R.id.openchrome)
launcher.setOnClickListener{
var launchIntent: Intent? = null
try {
launchIntent = packageManager.getLaunchIntentForPackage("com.android.chrome")
} catch (ignored: Exception) {
}
if (launchIntent == null) {
startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + "com.android.chrome")))
} else {
startActivity(launchIntent)
}
}
}
}我已经在我的android上安装了铬。
但是当我按下“打开铬”按钮时,铬就不会打开了。相反,切换到playstore。
发布于 2022-09-06 15:57:05
尝尝这个
try {
launchIntent =packageManager.getLaunchIntentForPackage("com.android.chrome")
startActivity(launchIntent)
} catch (E: Exception) {
println("Package not found")
}https://stackoverflow.com/questions/70997828
复制相似问题