Search in sources :

Example 56 with AssetManager

use of android.content.res.AssetManager in project BetterBatteryStats by asksven.

the class SystemAppInstaller method copyAsset.

private static void copyAsset(Context ctx, String assetName, String targetPath) {
    AssetManager assetManager = ctx.getAssets();
    String[] files = null;
    try {
        files = assetManager.list("");
    } catch (IOException e) {
        Log.e("tag", e.getMessage());
    }
    for (String filename : files) {
        if (filename.equals(assetName)) {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = assetManager.open(filename);
                String strOutFile = targetPath + "/" + filename;
                out = new FileOutputStream(strOutFile);
                copyFile(in, out);
                in.close();
                in = null;
                out.flush();
                out.close();
                out = null;
            } catch (Exception e) {
                Log.e(TAG, "An error occured while reading " + filename);
            }
        }
    }
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 57 with AssetManager

use of android.content.res.AssetManager in project KeePassDX by Kunzisoft.

the class Kdb3 method testKeyfile.

private void testKeyfile(String dbAsset, String keyAsset, String password) throws Exception {
    Context ctx = getContext();
    File sdcard = Environment.getExternalStorageDirectory();
    String keyPath = sdcard.getAbsolutePath() + "/key";
    TestUtil.extractKey(ctx, keyAsset, keyPath);
    AssetManager am = ctx.getAssets();
    InputStream is = am.open(dbAsset, AssetManager.ACCESS_STREAMING);
    ImporterV3 importer = new ImporterV3();
    importer.openDatabase(is, password, TestUtil.getKeyFileInputStream(ctx, keyPath));
    is.close();
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) ImporterV3(com.keepassdroid.database.load.ImporterV3) File(java.io.File)

Example 58 with AssetManager

use of android.content.res.AssetManager in project KeePassDX by Kunzisoft.

the class Kdb3Twofish method testReadTwofish.

public void testReadTwofish() throws Exception {
    Context ctx = getContext();
    AssetManager am = ctx.getAssets();
    InputStream is = am.open("twofish.kdb", AssetManager.ACCESS_STREAMING);
    ImporterV3 importer = new ImporterV3();
    PwDatabaseV3 db = importer.openDatabase(is, "12345", null);
    assertTrue(db.algorithm == PwEncryptionAlgorithm.Twofish);
    is.close();
}
Also used : Context(android.content.Context) PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) ImporterV3(com.keepassdroid.database.load.ImporterV3)

Example 59 with AssetManager

use of android.content.res.AssetManager in project KeePassDX by Kunzisoft.

the class Kdb4 method testComposite.

public void testComposite() throws IOException, InvalidDBException {
    Context ctx = getContext();
    AssetManager am = ctx.getAssets();
    InputStream is = am.open("keyfile.kdbx", AssetManager.ACCESS_STREAMING);
    ImporterV4 importer = new ImporterV4();
    importer.openDatabase(is, "12345", TestUtil.getKeyFileInputStream(ctx, TestUtil.getSdPath("key")));
    is.close();
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) ByteArrayInputStream(java.io.ByteArrayInputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) InputStream(java.io.InputStream) ImporterV4(com.keepassdroid.database.load.ImporterV4)

Example 60 with AssetManager

use of android.content.res.AssetManager in project KeePassDX by Kunzisoft.

the class Kdb4 method testCompositeBinary.

public void testCompositeBinary() throws IOException, InvalidDBException {
    Context ctx = getContext();
    AssetManager am = ctx.getAssets();
    InputStream is = am.open("keyfile-binary.kdbx", AssetManager.ACCESS_STREAMING);
    ImporterV4 importer = new ImporterV4();
    importer.openDatabase(is, "12345", TestUtil.getKeyFileInputStream(ctx, TestUtil.getSdPath("key-binary")));
    is.close();
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) ByteArrayInputStream(java.io.ByteArrayInputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) InputStream(java.io.InputStream) ImporterV4(com.keepassdroid.database.load.ImporterV4)

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