你怎么能得到从应用程序的(布局)XML变量的清单版本号? [英] How can you get the Manifest Version number from the App's (Layout) XML variables?

查看:150
本文介绍了你怎么能得到从应用程序的(布局)XML变量的清单版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一种方式来引用的code的主要部分项目的清单版本号。我一直在做,直至现在是链接在一个字符串的XML文件的清单(@字符串/版)的版本号。我想这样做是做它周围的其他方式,一个XML字符串变量链接到清单中的版本。原因?我想只需要改变在一个位置,清单文件的版本号。有没有办法做到这一点?谢谢!

I would like to have a way to reference the project's manifest version number in the main part of the code. What I have been doing up until now is to link the version number in a String XML file to the manifest (@string/Version). What I would like to do is to do it the other way around, link a string XML variable to the version in the manifest. The reason? I'd like to only have to change the version number in one location, the manifest file. Is there any way to do this? Thanks!

推荐答案

有没有办法直接获取的版本出来,但有两种解决方法可以做。

There is not a way to directly get the version out, but there are two work-arounds that could be done.

  1. 版本可以被存储在资源串,并放置到清单的条件:

  1. The version could be stored in a resource string, and placed into the manifest by:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.somepackage"
     android:versionName="@string/version" android:versionCode="20">

  • 人们可以创建自定义视图,并把它转换为XML。该视图将使用这个分配的名称:

  • One could create a custom view, and place it into the XML. The view would use this to assign the name:

    context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    

  • 无论这些解决方案将允许将版本名称中的XML。不幸的是,没有一个很好的简单的解决方案,如 android.R.string.version 或类似的东西。

    Either of these solutions would allow for placing the version name in XML. Unfortunately there isn't a nice simple solution, like android.R.string.version or something like that.

    这篇关于你怎么能得到从应用程序的(布局)XML变量的清单版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆