Example usage for android.content ContextWrapper getApplicationInfo

List of usage examples for android.content ContextWrapper getApplicationInfo

Introduction

In this page you can find the example usage for android.content ContextWrapper getApplicationInfo.

Prototype

@Override
    public ApplicationInfo getApplicationInfo() 

Source Link

Usage

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 www.  j ava 2 s .  co m*/
            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

/** Initialization routine called by the constructor. */
private void init(Context context) {
    // Exit if in the Eclipse graphical editor
    if (this.isInEditMode()) {
        return;/* w ww  .  jav a 2s  .co  m*/
    }

    this.context = context;

    this.readOcrSettings(context);

    this.determineScreenDimensions(context);

    File externalDir = this.context.getExternalFilesDir(null);
    this.tesseractDbDir = new File(externalDir.toString() + Constants.TESSERACT_ROOT_DIR);
    this.tesseractDbFile = new File(externalDir.toString() + Constants.TESSDATA_DIR,
            Constants.TESSERACT_DB_FILENAME);
    this.edictDbFile = new File(externalDir, Constants.EDICT_DB_FILENAME);
    this.namesDbFile = new File(externalDir, Constants.NAMES_DB_FILENAME);
    this.kanjiDbFile = new File(externalDir, Constants.KANJI_DB_FILENAME);
    this.kanjiDefFormatFile = new File(externalDir, Constants.KANJI_DEF_FORMAT_FILENAME);
    this.deinflectionDbFile = new File(externalDir, Constants.DEINFLECTION_DB_FILENAME);
    this.substitutionsDbFile = new File(externalDir, Constants.SUBSTITUTIONS_DB_FILENAME);
    this.freqDbFile = new File(externalDir, Constants.FREQ_DB_FILENAME);

    this.wordSetKnown = new WordSet(new File(externalDir, Constants.KNOWN_WORDS_FILENAME));
    this.wordSetTodo = new WordSet(new File(externalDir, Constants.TODO_WORDS_FILENAME));

    // Add OCR view
    this.ocrView = new OcrView(context);
    this.addView(this.ocrView);

    // Add dictionary view
    this.dicView = new WebView(context);
    this.dicView.setBackgroundColor(this.ocrSettingsDictBackgroundColor); // Make the background translucent.
    this.dicView.loadDataWithBaseURL(null, "<html><body></body></html>", "text/html", "utf-8", null);
    this.dicView.setVisibility(GONE);
    this.addView(this.dicView);

    // Set the path to eplkup
    ContextWrapper cw = new ContextWrapper(this.context);

    // Android 5.0 requires executables to be compiled with PIE (Position Independent Executable) support for security
    // reasons. However, PIE is not supported before Android 4.1, which is why we have 2 executables, one with
    // PIE and one without PIE.
    if (android.os.Build.VERSION.SDK_INT >= 20) {
        DicEpwing.setEplkupExe(cw.getApplicationInfo().dataDir + "/" + Constants.EPLKUP_FILENAME);
    } else {
        DicEpwing.setEplkupExe(cw.getApplicationInfo().dataDir + "/" + Constants.EPLKUP_NON_PIE_FILENAME);
    }
}

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
 *  *//*  www .j a  v a  2s .c  om*/
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;
}