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:org.apache.cordova.filesystemroots.FileSystemRoots.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    Activity activity = cordova.getActivity();
    Context context = activity.getApplicationContext();

    availableFilesystems = new HashMap<String, String>();
    availableFilesystems.put("files", context.getFilesDir().getAbsolutePath());
    availableFilesystems.put("files-external", context.getExternalFilesDir(null).getAbsolutePath());
    availableFilesystems.put("documents", new File(context.getFilesDir(), "Documents").getAbsolutePath());
    availableFilesystems.put("sdcard", Environment.getExternalStorageDirectory().getAbsolutePath());
    availableFilesystems.put("cache", context.getCacheDir().getAbsolutePath());
    availableFilesystems.put("cache-external", context.getExternalCacheDir().getAbsolutePath());
    availableFilesystems.put("root", "/");

    installedFilesystems = new HashSet<String>();

    String filesystemsStr = activity.getIntent().getStringExtra("androidextrafilesystems");
    if (filesystemsStr == null) {
        filesystemsStr = "files,files-external,documents,sdcard,cache,cache-external";
    }/*www.  ja v a 2 s  . com*/

    String[] filesystems = filesystemsStr.split(",");

    FileUtils filePlugin = (FileUtils) webView.pluginManager.getPlugin("File");
    if (filePlugin != null) {
        /* Register filesystems in order */
        for (String fsName : filesystems) {
            if (!installedFilesystems.contains(fsName)) {
                String fsRoot = availableFilesystems.get(fsName);
                if (fsRoot != null) {
                    File newRoot = new File(fsRoot);
                    if (newRoot.mkdirs() || newRoot.isDirectory()) {
                        filePlugin.registerFilesystem(new LocalFilesystem(fsName, cordova, fsRoot));
                        installedFilesystems.add(fsName);
                    } else {
                        Log.d(TAG, "Unable to create root dir for fileystem \"" + fsName + "\", skipping");
                    }
                } else {
                    Log.d(TAG, "Unrecognized extra filesystem identifier: " + fsName);
                }
            }
        }
    } else {
        Log.w(TAG, "File plugin not found; cannot initialize file-system-roots plugin");
    }

}

From source file:org.montanafoodhub.base.get.AdHub.java

protected List<Ad> readFromFile(Context context) {
    List<Ad> myAdArr = new ArrayList<Ad>();
    try {/*from w ww. j  a v  a 2 s  .c o m*/
        // getItem the time the file was last changed here
        File myFile = new File(context.getFilesDir() + "/" + fileName);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String lastRefreshTSStr = sdf.format(myFile.lastModified());
        Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr);
        lastRefreshTS = sdf.getCalendar();

        // create products from the file here
        InputStream inputStream = context.openFileInput(fileName);
        if (inputStream != null) {
            parseCSV(myAdArr, inputStream);
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        Log.e(HubInit.logTag, "File  (" + fileName + ") not found: " + e.toString());
    } catch (IOException e) {
        Log.e(HubInit.logTag, "Can not read file  (" + fileName + ") : " + e.toString());
    }
    Log.w(HubInit.logTag, "Number of Ad loaded: " + myAdArr.size());
    return myAdArr;
}

From source file:com.grarak.kerneladiutor.utils.Downloads.java

public Downloads(Context context) {
    try {//from   w w  w .j  ava2  s  . c om
        String json = Utils.existFile(context.getFilesDir() + "/downloads.json")
                ? Utils.readFile(context.getFilesDir() + "/downloads.json", false)
                : Utils.readAssetFile(context, "downloads.json");
        JSONArray devices = new JSONArray(json);
        for (int i = 0; i < devices.length(); i++) {
            JSONObject device = devices.getJSONObject(i);
            JSONArray vendors = device.getJSONArray("vendor");
            for (int x = 0; x < vendors.length(); x++)
                if (vendors.getString(x).equals(Utils.getVendorName())) {
                    JSONArray names = device.getJSONArray("device");
                    for (int y = 0; y < names.length(); y++)
                        if (names.getString(y).equals(Utils.getDeviceName()))
                            link = device.getString("link");
                }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.grarak.kerneladiutor.utils.tools.SupportedDownloads.java

public SupportedDownloads(Context context) {
    try {// www. j a v  a2 s  . c  om
        String json = Utils.existFile(context.getFilesDir() + "/downloads.json")
                ? Utils.readFile(context.getFilesDir() + "/downloads.json", false)
                : Utils.readAssetFile(context, "downloads.json");
        JSONArray devices = new JSONArray(json);
        for (int i = 0; i < devices.length(); i++) {
            JSONObject device = devices.getJSONObject(i);
            JSONArray vendors = device.getJSONArray("vendor");
            for (int x = 0; x < vendors.length(); x++) {
                if (vendors.getString(x).equals(Device.getVendor())) {
                    JSONArray names = device.getJSONArray("device");
                    for (int y = 0; y < names.length(); y++) {
                        if (names.getString(y).equals(Device.getDeviceName())) {
                            mLink = device.getString("link");
                        }
                    }
                }
            }
        }
    } catch (JSONException e) {
        Utils.toast("Failed to read downloads.json " + e.getMessage(), context);
    }
}

From source file:be.uclouvain.multipathcontrol.stats.JSONSender.java

public JSONSender(Context context, String name, StatsCategories category) {
    this.category = category;
    this.name = name;
    this.prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE);
    this.xmlFilePath = context.getFilesDir().getParent() + File.separator + "shared_prefs" + File.separator
            + name + ".xml";

    Map<String, ?> map = prefs.getAll();
    if (map == null || !map.containsKey(SaveDataAbstract.PREFS_TIMESTAMP))
        this.jsonObject = null;
    else//from w w  w .  j  av  a  2  s.  c om
        this.jsonObject = new JSONObject(map);
}

From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java

private String getLogFileName(Context context) throws IOException {

    File logPath = context.getFilesDir();
    File logFile = new File(logPath, LOG_FILE_NAME);
    return logFile.getAbsolutePath().toString();

}

From source file:com.coinblesk.client.utils.upgrade.UpgradeUtils.java

private boolean migrateFrom_v1_0_262(Context context) {
    // these directories were used by the object store
    // if any of these exist, we migrate from an existing wallet.
    File objectStoreMain = new File(context.getFilesDir(), "mainnet_wallet_" + "_uuid_object_storage");
    File objectStoreTest = new File(context.getFilesDir(), "testnet_wallet_" + "_uuid_object_storage");
    return objectStoreMain.exists() || objectStoreTest.exists();
}

From source file:org.montanafoodhub.base.get.OrderHub.java

protected List<Order> readFromFile(Context context) {
    List<Order> myOrderArr = new ArrayList<Order>();
    try {//from w w  w. j av a2s.  com
        // getItem the time the file was last changed here
        File myFile = new File(context.getFilesDir() + "/" + fileName);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String lastRefreshTSStr = sdf.format(myFile.lastModified());
        Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr);
        lastRefreshTS = sdf.getCalendar();

        // create products from the file here
        InputStream inputStream = context.openFileInput(fileName);
        if (inputStream != null) {
            parseCSV(myOrderArr, inputStream);
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        Log.e(HubInit.logTag, "File  (" + fileName + ") not found: " + e.toString());
    } catch (IOException e) {
        Log.e(HubInit.logTag, "Can not read file  (" + fileName + ") : " + e.toString());
    } catch (ParseException pe) {
        Log.e(HubInit.logTag, "Can't parse Order date  (" + fileName + ") : " + pe.toString());
    }
    Log.w(HubInit.logTag, "Number of orders loaded: " + myOrderArr.size());
    return myOrderArr;
}

From source file:org.montanafoodhub.base.get.InitHub.java

protected void readFromFile(Context context) {
    try {//from  ww w. jav  a  2 s  .  com
        // getItem the time the file was last changed here
        File myFile = new File(context.getFilesDir() + "/" + fileName);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String lastRefreshTSStr = sdf.format(myFile.lastModified());
        Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr);
        lastRefreshTS = sdf.getCalendar();

        // *** last line in the init wins!!!
        InputStream inputStream = context.openFileInput(fileName);
        if (inputStream != null) {
            parseCSV(inputStream);
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        Log.e(HubInit.logTag, "File  (" + fileName + ") not found: " + e.toString());
    } catch (IOException e) {
        Log.e(HubInit.logTag, "Can not read file  (" + fileName + ") : " + e.toString());
    }
    Log.w(HubInit.logTag, "Hub name initialized to: " + HubInit.getHubName());
}

From source file:org.wso2.emm.agent.api.DeviceState.java

public DeviceState(Context context) {
    this.context = context;
    this.info = new DeviceInfo(context);
    this.dataDirectory = new File(context.getFilesDir().getAbsoluteFile().toString());
    if (externalMemoryAvailable()) {
        this.externalStorageDirectoryList = ContextCompat.getExternalFilesDirs(context, null);
    }/*from  w w w  . j ava 2 s  .c o m*/
}