Example usage for android.content Context getFilesDir

List of usage examples for android.content Context getFilesDir

Introduction

In this page you can find the example usage for android.content Context getFilesDir.

Prototype

public abstract File getFilesDir();

Source Link

Document

Returns the absolute path to the directory on the filesystem where files created with #openFileOutput are stored.

Usage

From source file:interactivespaces.controller.android.InteractiveSpacesFrameworkAndroidBootstrap.java

/**
 * Create, configure, and start an OSGi framework instance. OO
 *
 * @return/*from   w  w  w  . j  a v  a  2 s .c  o m*/
 * @throws IOException
 * @throws BundleException
 */
private void createAndStartFramework(Map<String, String> bootstrapConfig, Context context)
        throws BundleException, IOException {
    Map<String, String> m = new HashMap<String, String>();

    File filesDir = context.getFilesDir();
    m.put("interactivespaces.rootdir", filesDir.getAbsolutePath());

    // m.putAll(System.getProperties());
    m.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);

    String delegations = getClassloaderDelegations(filesDir);
    if (delegations != null) {
        m.put(Constants.FRAMEWORK_BOOTDELEGATION, delegations);
    }

    m.put(Constants.FRAMEWORK_SYSTEMPACKAGES, getSystemPackages());

    m.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "log4j.properties");

    File file = new File(filesDir, "plugins-cache");
    file.mkdirs();
    m.put(Constants.FRAMEWORK_STORAGE, file.getCanonicalPath());

    m.put("felix.service.urlhandlers", "false");

    loadPropertyFiles(CONFIG_DIRECTORY, m);

    m.putAll(bootstrapConfig);

    framework = new Felix(m);
    framework.start();
}

From source file:csic.ceab.movelab.beepath.Util.java

public File[] listJSONFiles(Context context) {
    String dir = context.getFilesDir().getAbsolutePath();
    File directory = new File(dir, DIRECTORY_JSON_UPLOADQUEUE);
    File[] files = directory.listFiles();
    return files;
}

From source file:com.nuvolect.securesuite.webserver.connector.CmdUpload.java

private CmdUpload(Context context) {
    /**//from  www . ja  va  2 s . c o  m
     * An object keyed by filename holds an objects of file chunks.
     * fileUploads
     *     filename1
     *         chunk_0_5
     *         chunk_3_5
     *     filename2
     *         chunk_2_5
     *         chunk_4_5
     */
    fileUploads = new JsonObject();
    chunkDirPath = context.getFilesDir() + CConst.CHUNK;
    dataDir = context.getApplicationInfo().dataDir;
    clearChunkFiles();
}

From source file:interactivespaces.controller.android.InteractiveSpacesFrameworkAndroidBootstrap.java

/**
 * Start the framework up./* w  w  w.  j  a va  2  s .  com*/
 *
 * @param context
 *          the Android context to start the framework up in.
 */
public void startup(Map<String, String> config, Context context) {
    AssetManager assetManager = context.getAssets();

    try {
        createCoreServices(context);

        copyInitialBootstrapAssets(assetManager, context.getFilesDir());

        getBootstrapBundleJars(assetManager, BUNDLE_DIRECTORY_BOOTSTRAP);

        // If no bundle JAR files are in the directory, then exit.
        if (initialBundles.isEmpty() && finalBundles.isEmpty()) {
            System.out.println("No bundles to install.");
        }

        createAndStartFramework(config, context);

        registerCoreServices();

        List<Bundle> bundleList = new ArrayList<Bundle>();

        // Install bundle JAR files and remember the bundle objects.
        BundleContext ctxt = framework.getBundleContext();
        ctxt.addBundleListener(new BundleListener() {

            @Override
            public void bundleChanged(BundleEvent event) {
                bundleChangeEvent(event);
            }

        });

        isSystemActivator = new GeneralInteractiveSpacesSupportActivator();
        isSystemActivator.start(framework.getBundleContext());

        OsgiControllerActivator isControllerActivator = new OsgiControllerActivator();
        isControllerActivator.start(framework.getBundleContext());

        startBundles(assetManager, ctxt, bundleList, initialBundles, false);
        startBundles(assetManager, ctxt, bundleList, finalBundles, true);
    } catch (Exception ex) {
        System.err.println("Error starting framework: " + ex);
        ex.printStackTrace();
        System.exit(0);
    }
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.AuthorizationProcessManager.java

public AuthorizationProcessManager(Context context, AuthorizationManagerPreferences preferences) {
    this.logger = Logger.getLogger(Logger.INTERNAL_PREFIX + AuthorizationProcessManager.class.getSimpleName());

    this.preferences = preferences;
    this.authorizationQueue = new ConcurrentLinkedQueue<>();
    this.jsonSigner = new DefaultJSONSigner();

    File keyStoreFile = new File(context.getFilesDir().getAbsolutePath(), "mfp.keystore");
    String uuid = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    certificateStore = new CertificateStore(keyStoreFile, uuid);

    //case where the shared preferences were deleted but the certificate is saved in the keystore
    if (preferences.clientId.get() == null && certificateStore.isCertificateStored()) {
        try {//from ww  w .  ja v a2s .  c  o m
            X509Certificate certificate = certificateStore.getCertificate();
            preferences.clientId.set(CertificatesUtility.getClientIdFromCertificate(certificate));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //generate new random session id
    sessionId = UUID.randomUUID().toString();
}

From source file:com.panoskrt.dbadapter.DBAdapter.java

public void downloadDB(Context context, String dbName, String urlLink) {
    try {//  w  ww .  ja  v a 2 s . com
        URL url = new URL(urlLink);
        URLConnection ucon = url.openConnection();

        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(50);

        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        FileOutputStream fos = context.openFileOutput(dbName, Context.MODE_PRIVATE);
        fos.write(baf.toByteArray());
        fos.close();

        File dbFile = new File(context.getFilesDir() + "/" + dbName);
        InputStream in = new FileInputStream(dbFile);
        OutputStream out = new FileOutputStream(dbPath + dbName);
        bufCopy(in, out);
        dbFile.delete();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:utils.bobo.com.boboutils.App.appwidget.CustomViewFileProvider.java

/**
 * Parse and return {@link PathStrategy} for given authority as defined in
 * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code &lt;meta-data>}.
 *
 * @see #getPathStrategy(Context, String)
 *///from   w  w w  . j  av  a 2  s  .c  om
private static PathStrategy parsePathStrategy(Context context, String authority)
        throws IOException, XmlPullParserException {
    final SimplePathStrategy strat = new SimplePathStrategy(authority);

    final ProviderInfo info = context.getPackageManager().resolveContentProvider(authority,
            PackageManager.GET_META_DATA);
    final XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(),
            META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException("Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
    }

    int type;
    while ((type = in.next()) != END_DOCUMENT) {
        if (type == START_TAG) {
            final String tag = in.getName();

            final String name = in.getAttributeValue(null, ATTR_NAME);
            String path = in.getAttributeValue(null, ATTR_PATH);

            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = buildPath(DEVICE_ROOT, path);
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = buildPath(context.getFilesDir(), path);
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = buildPath(context.getCacheDir(), path);
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = buildPath(Environment.getExternalStorageDirectory(), path);
            }

            if (target != null) {
                strat.addRoot(name, target);
            }
        }
    }

    return strat;
}

From source file:com.mattprecious.telescope.FileProvider.java

/**
 * Parse and return {@link PathStrategy} for given authority as defined in
 * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code &lt;meta-data>}.
 *
 * @see #getPathStrategy(Context, String)
 *///from w w  w . j a  va 2s  .c o m
private static PathStrategy parsePathStrategy(Context context, String authority)
        throws IOException, XmlPullParserException {
    final SimplePathStrategy strat = new SimplePathStrategy(authority);

    final ProviderInfo info = context.getPackageManager().resolveContentProvider(authority,
            PackageManager.GET_META_DATA);
    final XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(),
            META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException("Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
    }

    int type;
    while ((type = in.next()) != END_DOCUMENT) {
        if (type == START_TAG) {
            final String tag = in.getName();

            final String name = in.getAttributeValue(null, ATTR_NAME);
            String path = in.getAttributeValue(null, ATTR_PATH);

            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = buildPath(DEVICE_ROOT, path);
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = buildPath(context.getFilesDir(), path);
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = buildPath(context.getCacheDir(), path);
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = buildPath(Environment.getExternalStorageDirectory(), path);
            } else if (TAG_EXTERNAL_APP.equals(tag)) {
                try {
                    // This sometimes causes an exception on API level 19
                    // Just avoid this specific file provider, so we can try to keep going
                    target = buildPath(context.getExternalFilesDir(null), path);
                } catch (NullPointerException npe) {
                    npe.printStackTrace();
                }
            }

            if (target != null) {
                strat.addRoot(name, target);
            }
        }
    }

    return strat;
}

From source file:com.hippo.content.FileProvider.java

/**
 * Parse and return {@link PathStrategy} for given authority as defined in
 * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}.
 *
 * @see #getPathStrategy(Context, String)
 *///  w  ww .  java2 s .c  o  m
private static PathStrategy parsePathStrategy(Context context, String authority)
        throws IOException, XmlPullParserException {
    final SimplePathStrategy strat = new SimplePathStrategy(authority);

    final ProviderInfo info = context.getPackageManager().resolveContentProvider(authority,
            PackageManager.GET_META_DATA);
    final XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(),
            META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException("Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
    }

    int type;
    while ((type = in.next()) != END_DOCUMENT) {
        if (type == START_TAG) {
            final String tag = in.getName();

            final String name = in.getAttributeValue(null, ATTR_NAME);
            String path = in.getAttributeValue(null, ATTR_PATH);

            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = DEVICE_ROOT;
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = context.getFilesDir();
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = context.getCacheDir();
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = Environment.getExternalStorageDirectory();
            } else if (TAG_EXTERNAL_FILES.equals(tag)) {
                File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null);
                if (externalFilesDirs.length > 0) {
                    target = externalFilesDirs[0];
                }
            } else if (TAG_EXTERNAL_CACHE.equals(tag)) {
                File[] externalCacheDirs = ContextCompat.getExternalCacheDirs(context);
                if (externalCacheDirs.length > 0) {
                    target = externalCacheDirs[0];
                }
            }

            if (target != null) {
                strat.addRoot(name, buildPath(target, path));
            }
        }
    }

    return strat;
}