Android:自定义应用程序属性,可以通过包管理器访问吗?

发布于 2025-01-05 01:12:27 字数 286 浏览 0 评论 0原文

为了工作,我维护一个内部“市场”,可以上传和下载新的应用程序版本。我还维护一个启动器,可以从我们的许多应用程序中进行选择并启动它们(有些是相同的应用程序,但“品牌”不同)。我目前可以使用包名称和版本代码填充此列表,但我还想添加到 SVN 分支中。

我正在考虑使用一个脚本,将分支信息作为 XML 添加到清单中作为自定义属性或作为单独的 XML 文件。理想情况下,PackageManager 可以公开访问它。这可能吗?

或者,我可以通过编程方式更改 APK 名称吗?然后我可以使用“$name - $branch”作为新名称。

For work I maintain an internal 'market' where new app releases can be uploaded and downloaded. I also maintain a launcher that can select from our many apps and launch them (some are the same app 'branded' differently). I can currently populate this list with the package name and the version code, but I would also like to add in the SVN branch.

I was thinking about having a script that would add the branch info as XML either to the manifest as a custom attribute or as a separate XML file. Ideally, this could be accessible publicly by the PackageManager. Is this possible?

Alternatively, can I programmatically change the APK name? Then I could use "$name - $branch" as the new name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以可爱出名 2025-01-12 01:12:27

我正在考虑使用一个脚本,将分支信息作为 XML 添加到清单中作为自定义属性或作为单独的 XML 文件。理想情况下,PackageManager 可以公开访问它。这可能吗?

您已将 元素添加到组件的元素(例如 ),并通过 PackageManager 访问元数据 XML 内容code>:

    <receiver android:name="com.commonsware.cwac.wakeful.AlarmReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>

        <meta-data
            android:name="com.commonsware.cwac.wakeful"
            android:resource="@xml/wakeful"/>
    </receiver>

组件将通过如下代码访问元数据:

PackageManager pm=ctxt.getPackageManager();
ComponentName cn=new ComponentName(ctxt, getClass());
ActivityInfo ai=pm.getReceiverInfo(cn, PackageManager.GET_META_DATA);
XmlResourceParser xpp=ai.loadXmlMetaData(pm, "com.commonsware.cwac.wakeful");

然后,您的自定义构建过程可以调整 指向的 XML 资源以包含您想要的任何内容。

或者,我可以通过编程方式更改 APK 名称吗?

您可以在硬盘上随意命名 APK 文件,但我不会指望该名称在安装过程中保持不变。

I was thinking about having a script that would add the branch info as XML either to the manifest as a custom attribute or as a separate XML file. Ideally, this could be accessible publicly by the PackageManager. Is this possible?

You have add a <meta-data> element to a component's element (e.g., <activity>) and access the metadata XML content via PackageManager:

    <receiver android:name="com.commonsware.cwac.wakeful.AlarmReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>

        <meta-data
            android:name="com.commonsware.cwac.wakeful"
            android:resource="@xml/wakeful"/>
    </receiver>

The component would access the metadata through code like this:

PackageManager pm=ctxt.getPackageManager();
ComponentName cn=new ComponentName(ctxt, getClass());
ActivityInfo ai=pm.getReceiverInfo(cn, PackageManager.GET_META_DATA);
XmlResourceParser xpp=ai.loadXmlMetaData(pm, "com.commonsware.cwac.wakeful");

Your custom build process could then adjust the XML resource pointed to by <meta-data> to contain whatever you want.

Alternatively, can I programmatically change the APK name?

You can name the APK file whatever you want on your hard drive, but I would not count on that name remaining intact through the installation process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文