[AS3.0.1]meta-data和manifestPlace

2018-01-13  本文已影响0人  小南2017

一篇关于meta-data的转载记录


<application ... >
    <meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</application>
        try {
            ApplicationInfo info = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            Log.e("info", info.metaData.getString("TEST_KEY"));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

<activity ... >
    <meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</activity>
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.e("info", info.metaData.getString("TEST_KEY"));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

<service ... >
    <meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</service>
        try {
            ServiceInfo info = getPackageManager().getServiceInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.e("info", info.metaData.getString("TEST_KEY"));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

<receiver ... >
    <meta-data android:name="TEST_KEY" android:value="${test_key}"/>
</receiver>
        try {
            ActivityInfo info = getPackageManager().getReceiverInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.e("info", info.metaData.getString("TEST_KEY"));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

manifestPlaceholders使用

在build.gradle的多版本中设置

            manifestPlaceholders = ["test_key": "修改的内容"]

好比如下

    productFlavors{
        dev{
            manifestPlaceholders = ["test_key": "测试版key"]
        }
        free{
            applicationIdSuffix ".free"
            manifestPlaceholders = ["test_key": "Free版key"]
        }
    }

效果如下


测试 Free

资料

Android获取Manifest中<meta-data>元素的值

使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中<meta-data>变量的值

上一篇下一篇

猜你喜欢

热点阅读