如何在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
相关产品推荐
相关产品推荐

