How to open the Google Play Store directly from my Android application?

后端 未结 23 2718
既然无缘
既然无缘 2020-11-22 02:00

I have open the Google Play store using the following code

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse(\"https://play.goo         


        
23条回答
  •  伪装坚强ぢ
    2020-11-22 02:18

    My kotlin entension function for this purpose

    fun Context.canPerformIntent(intent: Intent): Boolean {
            val mgr = this.packageManager
            val list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
            return list.size > 0
        }
    

    And in your activity

    val uri = if (canPerformIntent(Intent(Intent.ACTION_VIEW, Uri.parse("market://")))) {
                Uri.parse("market://details?id=" + appPackageName)
            } else {
                Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)
            }
            startActivity(Intent(Intent.ACTION_VIEW, uri))
    

提交回复
热议问题