List of usage examples for android.content ContextWrapper ContextWrapper
public ContextWrapper(Context base)
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String GetAppRoot(String AppName) { String sRet = sErrorPrefix + " internal error [no context]"; Context ctx = contextWrapper.getApplicationContext(); if (ctx != null) { try {//from w ww . j a v a 2 s.c om Context appCtx = ctx.createPackageContext(AppName, 0); ContextWrapper appCtxW = new ContextWrapper(appCtx); sRet = appCtxW.getApplicationInfo().dataDir; appCtxW = null; appCtx = null; ctx = null; System.gc(); } catch (NameNotFoundException e) { e.printStackTrace(); } } return (sRet); }
From source file:net.robotmedia.acv.ui.widget.OcrLayout.java
/** Copy OCR assets to the application folder in external storage. * http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard * *//*from w ww. ja va2 s.c o m*/ private boolean copyOcrAssets() { AssetManager assetManager = this.context.getAssets(); ContextWrapper cw = new ContextWrapper(this.context); String[] files = null; File externalDir = this.context.getExternalFilesDir(null); File tessdataDir = new File(externalDir.getPath() + Constants.TESSDATA_DIR); // Create the Tesseract directory structure if it doesn't exist if (!tessdataDir.exists()) { tessdataDir.mkdirs(); } try { files = assetManager.list(""); } catch (IOException e) { Log.e(LOG_TAG, "copyOcrAssets() failed to get asset file list!" + e); return false; } for (String filename : files) { InputStream in = null; OutputStream out = null; // Only store expected files if (filename.equals(Constants.EDICT_DB_FILENAME) || filename.equals(Constants.TESSERACT_DB_FILENAME) || filename.equals(Constants.DEINFLECTION_DB_FILENAME) || filename.equals(Constants.SUBSTITUTIONS_DB_FILENAME) || filename.equals(Constants.EPLKUP_FILENAME) || filename.equals(Constants.EPLKUP_NON_PIE_FILENAME) || filename.equals(Constants.FREQ_DB_FILENAME)) { try { in = assetManager.open(filename); File outFile; if (filename.equals(Constants.TESSERACT_DB_FILENAME)) { outFile = new File(tessdataDir, filename); } else if (filename.equals(Constants.EPLKUP_FILENAME)) { outFile = new File(cw.getApplicationInfo().dataDir + "/" + Constants.EPLKUP_FILENAME); } else if (filename.equals(Constants.EPLKUP_NON_PIE_FILENAME)) { outFile = new File( cw.getApplicationInfo().dataDir + "/" + Constants.EPLKUP_NON_PIE_FILENAME); } else { outFile = new File(externalDir, filename); } out = new FileOutputStream(outFile); FileUtils.copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; // Give eplkup execute permissions if (filename.equals(Constants.EPLKUP_FILENAME)) { ShellUtils.chmod(cw.getApplicationInfo().dataDir + "/" + Constants.EPLKUP_FILENAME, "744"); } else if (filename.equals(Constants.EPLKUP_NON_PIE_FILENAME)) { ShellUtils.chmod(cw.getApplicationInfo().dataDir + "/" + Constants.EPLKUP_NON_PIE_FILENAME, "744"); } } catch (IOException e) { Log.e(LOG_TAG, "copyOcrAssets() copy failed!" + e); return false; } } } return true; }