ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

在Android快捷方式中使用变量功能xml?

2019-06-23 01:21:09  阅读:308  来源: 互联网

标签:android shortcuts


我正在使用Androidshortcut功能,我有以下xml:

<shortcuts
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut
        android:shortcutId="some_id"
        android:enabled="true"
        android:icon="@drawable/ic_icon"
        android:shortcutShortLabel="@string/short_label"
        android:shortcutLongLabel="@string/long_label"
        tools:targetApi="n_mr1">
        <intent
            android:action="android.intent.action.MAIN"
            android:targetPackage="my.package"
            android:targetClass="my.package.MainActivity" />
    </shortcut>
</shortcuts>

有这样的,它没有问题.

我可以在快捷方式xml文件中使用变量,例如在AndroidManifest.xml中我可以这样做:

<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>

所以我想对快捷方式有相同的行为,但不知何故它不起作用:

<intent
    android:action="android.intent.action.MAIN"
    android:targetPackage="${applicationId}"
    android:targetClass="my.package.MainActivity" />

你知道如何在这里使用变量吗?

我想这样做的原因是我们有多个具有不同包名的环境:my.package.test,my.package.debug,my.package.hotfix等…

解决方法:

我创建了一个插件,可以在资源中使用manifestPlaceholders,并且可以与android gradle插件的3.0.0版一起使用

https://github.com/timfreiheit/ResourcePlaceholdersPlugin

的src / main / RES / shortcuts.xml:

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut ...>

        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.test.MainActivity"
            android:targetPackage="${applicationId}"/>
    </shortcut>
</shortcuts>

标签:android,shortcuts
来源: https://codeday.me/bug/20190623/1266177.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有