【发布时间】:2020-06-24 16:36:04
【问题描述】:
我想从应用程序库或 Playstore 安装配套应用程序,无论是在华为还是非华为设备上可用。
今天我打开 playstore 的工作代码是:
val appId = "com.my.app.i.want.to.install"
val installAppMarketIntent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appId))
val installAppUrlIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id="+appId))
try {
activity.startActivity(installAppMarketIntent)
}catch (anfe: android.content.ActivityNotFoundException){
activity.startActivity(installAppUrlIntent)
}finally {
activity!!.finish()
}
我应该为华为设备添加验证吗?或者这个意图将适用于带有 AppGallery 的华为设备?
【问题讨论】:
-
我觉得很好。您是否尝试过并且有任何错误?理想情况下,如果应用程序库支持,您只需使用
market://URI 方案。 -
避免!!运算符,activity?.finish() 更好,从不抛出。
标签: java android kotlin huawei-mobile-services appgallery