Example usage for android.content.res AssetManager close

List of usage examples for android.content.res AssetManager close

Introduction

In this page you can find the example usage for android.content.res AssetManager close.

Prototype

@Override
public void close() 

Source Link

Document

Close this asset manager.

Usage

From source file:Main.java

public static String getMetaData(Context app, String name) {
    Bundle bundle = app.getApplicationInfo().metaData;
    if (bundle != null) {
        return bundle.getString(name);
    } else {/*w  w  w  .jav a2s  .  c  om*/
        XmlResourceParser parser = null;
        AssetManager assmgr = null;

        try {
            assmgr = (AssetManager) AssetManager.class.newInstance();
            Method e = AssetManager.class.getDeclaredMethod("addAssetPath", new Class[] { String.class });
            e.setAccessible(true);
            int cookie = ((Integer) e.invoke(assmgr, new Object[] { app.getApplicationInfo().sourceDir }))
                    .intValue();
            if (cookie != 0) {
                String ANDROID_RESOURCES = "http://schemas.android.com/apk/res/android";
                parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
                boolean findAppMetadata = false;
                int event = parser.getEventType();
                while (event != 1) {
                    switch (event) {
                    case 2:
                        String nodeName = parser.getName();
                        String metadataName;
                        if ("meta-data".equals(nodeName)) {
                            findAppMetadata = true;
                            metadataName = parser.getAttributeValue(ANDROID_RESOURCES, "name");
                            if (metadataName.equals(name)) {
                                String var12 = parser.getAttributeValue(ANDROID_RESOURCES, "value");
                                return var12;
                            }
                        } else if (findAppMetadata) {
                            metadataName = null;
                            return metadataName;
                        }
                    default:
                        event = parser.next();
                    }
                }
            }
        } catch (Throwable var16) {
            var16.printStackTrace();
        } finally {
            if (parser != null) {
                parser.close();
            }

            if (assmgr != null) {
                assmgr.close();
            }

        }

        return null;
    }
}