【发布时间】:2018-04-20 08:41:46
【问题描述】:
所以我正在处理冲突。我正在尝试从我的应用程序中启动 google play 商店,我已经实现了该功能。但是,我只能硬编码 URI 中的包值才能使其工作。我需要一种可以使用 getPackageName() 并从 google play store 返回正确的方法。
在 URI 中有效的 Google Play 商店包名称:org.horaapps.leafpic
包名 getPackageName() 返回:org.horaapps.leafpic.debug
这是启动google play的代码:
//Launches to the app in google play, if the package name ever does change you can do this
//by changing the org section of the URI below. -beastlyCoder
Uri uri = Uri.parse("market://details?id=org.horaapps.leafpic"); //dont want hardcoded value
Log.d("tag", getApplicationContext().getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
try
{
startActivity(myAppLinkToMarket);
} catch (ActivityNotFoundException e)
{
Toast.makeText(this, " unable to find market app", Toast.LENGTH_SHORT);
}
我怎样才能在最后删除调试,以便两个包可以对应,(注意:这是一个开源项目,所以我不希望对代码进行任何重大更改,例如更改包结构和所有这些.)
【问题讨论】: