【问题标题】:Removing part of package name Android删除部分包名Android
【发布时间】: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);
}

我怎样才能在最后删除调试,以便两个包可以对应,(注意:这是一个开源项目,所以我不希望对代码进行任何重大更改,例如更改包结构和所有这些.)

【问题讨论】:

    标签: java android


    【解决方案1】:

    将您的构建变体设置为 release 并将其添加到您的应用级别 build.gradle

    buildTypes {
        release {
            applicationId "org.horaapps.leafpic"
        }
    
        debug {
            applicationIdSuffix ""
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-08
      • 2017-09-16
      • 2014-10-22
      • 2020-05-14
      • 1970-01-01
      • 2019-02-05
      • 2014-03-08
      相关资源
      最近更新 更多