I have kotlin apps program like this:
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)
}
}
}
}
I have installed chrome on my android.
but when i press "open chrome" button, chrome doesn’t open. instead switch to playstore.
2
Answers
try this
You need to go
AndroidManifest.xml
and addAfter that in your code:
and its done!