raw 文件读取

raw:

<?xml version="2.0" encoding="UTF-8"?>
<notificationInfos>

    <notificationInfo
        app_pkg="com.lili"
        icon_color="lili_color"
        icon_white="lili_white"
</notificationInfos>
/>


public static HashMap<String, int[]> readNotificationIconInfo(Context context) {

        final HashMap<String, int[]> notificationIconsMap = new HashMap<String, int[]>();
        InputStream notiInfosStream = null;
        try {
            Resources res = context.getResources();
            notiInfosStream = res.openRawResource(R.raw.popular3p_notification_icons);
            XmlPullParser xrp = Xml.newPullParser();

            xrp.setInput(notiInfosStream, "utf-8");


            String packageName = "";
            int colorIconId = 0;
            int whiteIconId = 0;
            while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
                if (xrp.getEventType() == XmlResourceParser.START_TAG) {
                    if ("notificationInfo".equals(xrp.getName())) {
                        packageName = xrp.getAttributeValue(0);
                        colorIconId = res.getIdentifier(xrp.getAttributeValue(1), "drawable",
                                "com.android.systemui");
                        whiteIconId = res.getIdentifier(xrp.getAttributeValue(2), "drawable",
                                "com.android.systemui");
                    }
                } else if (xrp.getEventType() == XmlPullParser.END_TAG) {
                    if ("notificationInfo".equals(xrp.getName())) {
                        int[] icons = {colorIconId, whiteIconId};
                        notificationIconsMap.put(packageName, icons);
                    }
                } else if (xrp.getEventType() == XmlPullParser.TEXT) {
                }


                xrp.next();
            }
        } catch (Exception e) {
            LogUtils.e(TAG, "read xml error" + e);
            e.printStackTrace();
        } finally {
            closeQuietly(notiInfosStream);
        }
        return notificationIconsMap;
    }


    public static void closeQuietly(Closeable closeable) {
        if (null != closeable) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值