You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android应用内实现类似Facebook的应用下载弹窗?

实现类似Facebook推广Messenger的应用下载弹窗功能

我想要在自己的Android应用中,实现类似Facebook推广Messenger的应用下载弹窗功能,弹窗需提供从Google Play Store下载指定应用的选项。目前已编写如下Kotlin代码,用于检测目标应用是否已安装:若已安装则直接打开,未安装则跳转至Play Store对应应用页面。现需完成弹窗实现,效果如图所示。

val appPackageName = "com.facebook.orca"
val launchIntent: Intent? =
    packageManager.getLaunchIntentForPackage("com.facebook.orca")
try {
    if (launchIntent != null) {
        // We found the activity now start the activity
        //  launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        startActivity(launchIntent)
    }
    else {
        val intent = Intent(Intent.ACTION_VIEW).apply {
            data = Uri.parse(
                "https://play.google.com/store/apps/details?id=$appPackageName")
            setPackage("com.android.vending")
        }
        startActivity(intent)
        // startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + "com.facebook.orca")))
    }
} catch (ex: Exception) {

    val intent = Intent(Intent.ACTION_VIEW).apply {
        data = Uri.parse(
            "https://play.google.com/store/apps/details?id=$appPackageName")
        setPackage("com.android.vending")
    }
    startActivity(intent)
    // startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + "com.facebook.orca[enter image description here](https://i.sstatic.net/2q1Xh.png)")))
}

弹窗效果示例:
应用下载弹窗效果

内容的提问来源于stack exchange,提问作者kulb inte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 14:15:19