Search in sources :

Example 46 with AssetManager

use of android.content.res.AssetManager in project android_frameworks_base by crdroidandroid.

the class PackageParser method parseClusterPackage.

/**
     * Parse all APKs contained in the given directory, treating them as a
     * single package. This also performs sanity checking, such as requiring
     * identical package name and version codes, a single base APK, and unique
     * split names.
     * <p>
     * Note that this <em>does not</em> perform signature verification; that
     * must be done separately in {@link #collectCertificates(Package, int)}.
     */
private Package parseClusterPackage(File packageDir, int flags) throws PackageParserException {
    final PackageLite lite = parseClusterPackageLite(packageDir, 0);
    // When mOnlyPowerOffAlarmApps is true, only parse power off alarm packages
    if (mOnlyPowerOffAlarmApps) {
        if (!isPowerOffAlarmPackage(lite.packageName)) {
            throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "Not a powerOffAlarmApp: " + packageDir);
        }
    }
    if (!mOnlyPowerOffAlarmApps && mOnlyCoreApps && !lite.coreApp) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "Not a coreApp: " + packageDir);
    }
    final AssetManager assets = new AssetManager();
    try {
        // Load the base and all splits into the AssetManager
        // so that resources can be overriden when parsing the manifests.
        loadApkIntoAssetManager(assets, lite.baseCodePath, flags);
        if (!ArrayUtils.isEmpty(lite.splitCodePaths)) {
            for (String path : lite.splitCodePaths) {
                loadApkIntoAssetManager(assets, path, flags);
            }
        }
        final File baseApk = new File(lite.baseCodePath);
        final Package pkg = parseBaseApk(baseApk, assets, flags);
        if (pkg == null) {
            throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, "Failed to parse base APK: " + baseApk);
        }
        if (!ArrayUtils.isEmpty(lite.splitNames)) {
            final int num = lite.splitNames.length;
            pkg.splitNames = lite.splitNames;
            pkg.splitCodePaths = lite.splitCodePaths;
            pkg.splitRevisionCodes = lite.splitRevisionCodes;
            pkg.splitFlags = new int[num];
            pkg.splitPrivateFlags = new int[num];
            for (int i = 0; i < num; i++) {
                parseSplitApk(pkg, i, assets, flags);
            }
        }
        pkg.setCodePath(packageDir.getAbsolutePath());
        pkg.setUse32bitAbi(lite.use32bitAbi);
        return pkg;
    } finally {
        IoUtils.closeQuietly(assets);
    }
}
Also used : AssetManager(android.content.res.AssetManager) StrictJarFile(android.util.jar.StrictJarFile) File(java.io.File)

Example 47 with AssetManager

use of android.content.res.AssetManager in project SeeSik by GHHM.

the class DataBase method createTable.

//테이블 생성(user info, dailyList, intakeList)
public void createTable() {
    //To create userInfo, intakeList in database
    if (first) {
        // Create userInfo table
        userDB.execSQL("create table if not exists userInfo (age integer, gender integer);");
        // Create intakeList table
        userDB.execSQL("create table if not exists dailyList(date text,times integer,foodName text ,sugar int,na int,chol int,fat int );");
        userDB.execSQL("create table if not exists intakeList(date text, sugar int, na int, chol int, fat int, highestIngredient int);");
        File folder = new File("data/data/org.androidtown.myapplication/databases/");
        if (!folder.exists())
            folder.mkdir();
        File file = new File("data/data/org.androidtown.myapplication/databases/foodList.db");
        AssetManager assetManager = context.getAssets();
        try {
            file.createNewFile();
            InputStream is = assetManager.open("foodList.db");
            long filesize = is.available();
            byte[] tempdata = new byte[(int) filesize];
            is.read(tempdata);
            is.close();
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(tempdata);
            fos.close();
            first = false;
        } catch (Exception e) {
            Toast.makeText(context, "오류가 났어....", Toast.LENGTH_LONG).show();
        }
        foodDB = context.openOrCreateDatabase("foodList.db", MODE_PRIVATE, null);
        first = false;
        userDB.close();
        foodDB = context.openOrCreateDatabase("foodList.db", MODE_PRIVATE, null);
        foodDB.close();
    } else
        return;
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 48 with AssetManager

use of android.content.res.AssetManager in project bdcodehelper by boredream.

the class AssetsDatabaseManager method copyAssetsToFilesystem.

private boolean copyAssetsToFilesystem(String assetsSrc, String des) {
    Log.i(tag, "Copy " + assetsSrc + " to " + des);
    InputStream istream = null;
    OutputStream ostream = null;
    try {
        AssetManager am = context.getAssets();
        istream = am.open(assetsSrc);
        ostream = new FileOutputStream(des);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = istream.read(buffer)) > 0) {
            ostream.write(buffer, 0, length);
        }
        istream.close();
        ostream.close();
    } catch (Exception e) {
        e.printStackTrace();
        try {
            if (istream != null)
                istream.close();
            if (ostream != null)
                ostream.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        return false;
    }
    return true;
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream)

Example 49 with AssetManager

use of android.content.res.AssetManager in project android_frameworks_base by crdroidandroid.

the class Font method createFromAsset.

/**
     * @deprecated in API 16
     */
public static Font createFromAsset(RenderScript rs, Resources res, String path, float pointSize) {
    rs.validate();
    AssetManager mgr = res.getAssets();
    int dpi = res.getDisplayMetrics().densityDpi;
    long fontId = rs.nFontCreateFromAsset(mgr, path, pointSize, dpi);
    if (fontId == 0) {
        throw new RSRuntimeException("Unable to create font from asset " + path);
    }
    Font rsFont = new Font(fontId, rs);
    return rsFont;
}
Also used : AssetManager(android.content.res.AssetManager)

Example 50 with AssetManager

use of android.content.res.AssetManager in project android_frameworks_base by crdroidandroid.

the class PackageManagerShellCommand method getResources.

private Resources getResources(PackageItemInfo pii) throws RemoteException {
    Resources res = mResourceCache.get(pii.packageName);
    if (res != null)
        return res;
    ApplicationInfo ai = mInterface.getApplicationInfo(pii.packageName, 0, 0);
    AssetManager am = new AssetManager();
    am.addAssetPath(ai.publicSourceDir);
    res = new Resources(am, null, null);
    mResourceCache.put(pii.packageName, res);
    return res;
}
Also used : AssetManager(android.content.res.AssetManager) ApplicationInfo(android.content.pm.ApplicationInfo) Resources(android.content.res.Resources)

Aggregations

AssetManager (android.content.res.AssetManager)346 IOException (java.io.IOException)141 InputStream (java.io.InputStream)121 Resources (android.content.res.Resources)75 File (java.io.File)54 FileOutputStream (java.io.FileOutputStream)34 XmlResourceParser (android.content.res.XmlResourceParser)32 DisplayMetrics (android.util.DisplayMetrics)31 Bitmap (android.graphics.Bitmap)23 Configuration (android.content.res.Configuration)21 BufferedReader (java.io.BufferedReader)21 InputStreamReader (java.io.InputStreamReader)20 ArrayList (java.util.ArrayList)20 FileInputStream (java.io.FileInputStream)18 OutputStream (java.io.OutputStream)17 Context (android.content.Context)16 Intent (android.content.Intent)16 JsonParser (com.google.gson.JsonParser)16 ByteArrayInputStream (java.io.ByteArrayInputStream)16 Method (java.lang.reflect.Method)16