List of usage examples for android.content Context getFilesDir
public abstract File getFilesDir();
From source file:ca.ualberta.cs.expenseclaim.dao.ExpenseClaimDao.java
private void save(Context context) { Collections.sort(claimList, new Comparator<ExpenseClaim>() { @Override//from ww w. j av a 2 s .co m public int compare(ExpenseClaim lhs, ExpenseClaim rhs) { return lhs.getStartDate().compareTo(rhs.getStartDate()); } }); File file = new File(context.getFilesDir(), FILENAME); PrintWriter writer = null; try { writer = new PrintWriter(file); for (ExpenseClaim c : claimList) { JSONObject jo = new JSONObject(); jo.put("id", c.getId()); jo.put("name", c.getName()); jo.put("description", c.getDescription()); jo.put("startDate", c.getStartDate().getTime()); jo.put("endDate", c.getEndDate().getTime()); jo.put("status", c.getStatus()); writer.println(jo.toString()); } } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { writer.close(); } } }
From source file:com.coinblesk.client.utils.upgrade.UpgradeUtils.java
private void doMigrateFrom_v1_0_262(Context context, NetworkParameters migrationParams) throws IOException { Log.d(TAG, "********* MIGRATION FROM v1.0.262 - " + migrationParams.getId() + "*********"); final File rootDir = context.getFilesDir(); final File storageDir; final File archiveDir = new File(rootDir, "archive_" + System.currentTimeMillis()); final File walletFile; final File chainFile; final File newWalletFile; final File newChainFile; if (ClientUtils.isMainNet(migrationParams)) { String walletFilesPrefix = AppConfig.MainNetConfig.get().getWalletFilesPrefix(); storageDir = new File(rootDir, "mainnet_wallet__uuid_object_storage"); walletFile = new File(rootDir, "mainnet_wallet_.wallet"); newWalletFile = new File(rootDir, walletFilesPrefix + ".wallet"); chainFile = new File(rootDir, "mainnet_wallet_.spvchain"); newChainFile = new File(rootDir, walletFilesPrefix + ".spvchain"); } else if (ClientUtils.isTestNet(migrationParams)) { String walletFilesPrefix = AppConfig.TestNetConfig.get().getWalletFilesPrefix(); storageDir = new File(rootDir, "testnet_wallet__uuid_object_storage"); walletFile = new File(rootDir, "testnet_wallet_.wallet"); newWalletFile = new File(rootDir, walletFilesPrefix + ".wallet"); chainFile = new File(rootDir, "testnet_wallet_.spvchain"); newChainFile = new File(rootDir, walletFilesPrefix + ".spvchain"); } else {/* www.ja v a 2 s. com*/ throw new RuntimeException("Network params not supported (unknown): " + migrationParams.toString()); } final File keyFile = new File(storageDir, "ECKeyWrapper.json"); if (keyFile.exists() && walletFile.exists()) { // Keys: stored in ECKeyWrapper.json /* Key format (JSON): { "...uuid1...": { "isPublicOnly": true, "keyPayload": [...bytes (integers)...], "name": "remote_server_public_key", "uuid": "...uuid1..." }, "...uuid2...": { "isPublicOnly": false, "keyPayload": [...bytes (integers)...], "name": "remote_client_public_key", "uuid": "...uuid2..." } } */ Log.d(TAG, "Key file found: " + keyFile); String keyFileJson = FileUtils.readFileToString(keyFile); Type type = new TypeToken<Map<String, ECKeyWrapper>>() { }.getType(); // Note: do not use gson from serializeutils (key is not stored in base64). Map<String, ECKeyWrapper> keys = new Gson().fromJson(keyFileJson, type); ECKey serverKey = null; ECKey clientKey = null; for (ECKeyWrapper key : keys.values()) { if (key.isPublicOnly && key.name.equals("remote_server_public_key")) { serverKey = ECKey.fromPublicOnly(key.keyPayload); } else if (!key.isPublicOnly && key.name.equals("remote_client_public_key")) { clientKey = ECKey.fromPrivate(key.keyPayload); } else { Log.d(TAG, "Unknown key name: " + key.name); } } if (clientKey != null && serverKey != null) { Log.d(TAG, "Found client and server keys - store in shared preferences."); try { /********** Actual Migration Code **********/ SharedPrefUtils.setClientKey(context, migrationParams, clientKey); SharedPrefUtils.setServerKey(context, migrationParams, serverKey, "n/a - migration"); Log.d(TAG, "Migrated keys:" + " clientPubKey=" + clientKey.getPublicKeyAsHex() + ", serverPubKey=" + serverKey.getPublicKeyAsHex()); // move wallet file Log.d(TAG, "Migrate wallet file: " + walletFile.toString() + " -> " + newWalletFile.toString()); FileUtils.copyFile(walletFile, newWalletFile); Log.d(TAG, "Migrate chain file: " + chainFile.toString() + " -> " + newChainFile.toString()); FileUtils.copyFile(chainFile, newChainFile); SharedPrefUtils.enableMultisig2of2ToCltvForwarder(context); // move everything to an archive file. Log.d(TAG, "Move old files to archive dir: " + archiveDir.toString()); FileUtils.moveToDirectory(storageDir, archiveDir, true); FileUtils.moveToDirectory(walletFile, archiveDir, true); FileUtils.moveToDirectory(chainFile, archiveDir, true); } catch (Exception e) { Log.d(TAG, "Exception: ", e); // clear the changes made. SharedPrefUtils.setClientKey(context, migrationParams, null); SharedPrefUtils.setServerKey(context, migrationParams, null, ""); if (newWalletFile.exists()) { newWalletFile.delete(); } } } } else { Log.d(TAG, "Key file or wallet file not found - no migration required - " + String.format( "keyFile: %s (exists: %s), walletFile: %s (exists: %s)", keyFile.toString(), keyFile.exists(), walletFile.toString(), walletFile.exists())); } Log.d(TAG, "********* MIGRATION FROM v1.0.262 FINISHED *********"); }
From source file:com.cihon.androidrestart_keven.activity.CarNumActivity.java
/** * /*from w w w. ja va 2 s .c o m*/ **/ public String takePicRootDir(Context context) { if (checkSDCardAvailable()) { return Environment.getExternalStorageDirectory() + File.separator; } else { return context.getFilesDir().getAbsolutePath() + File.separator; } }
From source file:com.adrguides.model.Guide.java
public void saveToDisk(Context context) throws IOException, JSONException { File dir = new File(context.getFilesDir(), "saved-" + sha256(getTitle() + "_" + getLanguage() + "_" + getCountry() + "_" + getVariant())); dir.mkdir();/*from w w w.j a v a 2 s. c om*/ File[] children = dir.listFiles(); for (File c : children) { c.delete(); } Map<String, String> processedimages = new HashMap<String, String>(); JSONObject jsonguide = new JSONObject(); jsonguide.put("address", getAddress()); jsonguide.put("title", getTitle()); jsonguide.put("description", getDescription()); jsonguide.put("author", getAuthor()); jsonguide.put("keywords", getKeywords()); jsonguide.put("language", getLanguage()); jsonguide.put("country", getCountry()); jsonguide.put("variant", getVariant()); JSONArray chapters = new JSONArray(); jsonguide.put("chapters", chapters); for (Place p : getPlaces()) { JSONObject chapter = new JSONObject(); chapters.put(chapter); chapter.put("id", p.getId()); chapter.put("title", p.getTitle()); JSONArray paragraphs = new JSONArray(); chapter.put("paragraphs", paragraphs); for (Section s : p.getSections()) { JSONObject section = new JSONObject(); paragraphs.put(section); section.put("text", s.getText()); section.put("read", s.getRead()); section.put("image", saveImage(context, processedimages, dir, s.getImageURL())); } } saveTextToFile(new File(dir, "guidebook.json"), jsonguide.toString()); saveTextToFile(new File(dir, "guidebook.title.txt"), getTitle()); saveTextToFile(new File(dir, "guidebook.description.txt"), getDescription()); saveTextToFile(new File(dir, "guidebook.author.txt"), getAuthor()); saveTextToFile(new File(dir, "guidebook.keywords.txt"), getKeywords()); saveTextToFile(new File(dir, "guidebook.locale.txt"), getLocale().getDisplayName()); if (getPlaces().size() > 0 && getPlaces().get(0).getSections().size() > 0 && getPlaces().get(0).getSections().get(0).getImageURL() != null) { saveBitmapToFile(context, new File(dir, "guidebook.image.png"), new URL(getPlaces().get(0).getSections().get(0).getImageURL())); } // setStored(true); }
From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java
void install(Context context, com.esminis.server.library.model.InstallPackage model, ServerControl serverControl, InstallPackageManager installPackageManager) throws Throwable { final File file = new File(context.getExternalFilesDir(null), "tmp_install"); final File targetDirectory = context.getFilesDir(); try {// w w w . j av a 2 s . co m stopServer(context, serverControl); download(context, model, file); sendBroadcast(context, STATE_UNINSTALL, 0); installPackageManager.setInstalled(null); uninstall(targetDirectory); sendBroadcast(context, STATE_UNINSTALL, 1); install(context, file, targetDirectory); } finally { if (file.isFile()) { //noinspection ResultOfMethodCallIgnored file.delete(); } } }
From source file:csh.cryptonite.Cryptonite.java
public static void cleanCache(Context context) { /* Delete directories */ deleteDir(context.getFilesDir()); deleteDir(context.getDir(DirectorySettings.BROWSEPNT, Context.MODE_PRIVATE)); deleteDir(context.getDir(DirectorySettings.DROPBOXPNT, Context.MODE_PRIVATE)); deleteDir(DirectorySettings.INSTANCE.openDir); deleteDir(DirectorySettings.INSTANCE.readDir); }
From source file:com.grarak.kerneladiutor.utils.json.Downloads.java
public Downloads(Context context) { try {/* w w w.j a v a2 s. com*/ String json; if (Utils.existFile("/res/kernel_adiutor_mod/downloads.json")) { json = Tools.readFile("/res/kernel_adiutor_mod/downloads.json", false); } else if (Utils.existFile(context.getFilesDir() + "/downloads.json")) { json = Tools.readFile(context.getFilesDir() + "/downloads.json", false); } else { json = 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:org.linphone.tools.OpenH264DownloadHelper.java
/** * Default values/*from www . ja va2 s. co m*/ * nameLib = "libopenh264-1.5.so" * urlDownload = "http://ciscobinary.openh264.org/libopenh264-1.5.0-android19.so.bz2" * nameFileDownload = "libopenh264-1.5.0-android19.so.bz2" */ public OpenH264DownloadHelper(Context context) { userData = new ArrayList<Object>(); licenseMessage = "OpenH264 Video Codec provided by Cisco Systems, Inc."; nameLib = "libopenh264.so"; urlDownload = "http://ciscobinary.openh264.org/libopenh264-1.5.0-android19.so.bz2"; nameFileDownload = "libopenh264-1.5.0-android19.so.bz2"; if (context.getFilesDir() != null) { fileDirection = context.getFilesDir().toString(); } }
From source file:com.almende.demo.conferenceApp.ConferenceAgent.java
/** * Inits the./* ww w . j a va 2 s. com*/ * * @param ctx * the ctx */ public void init(Context ctx) { ConferenceAgent.ctx = ctx; final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); final AgentConfig config = new AgentConfig(); config.setId(tm.getDeviceId()); final FileStateConfig stateConfig = new FileStateConfig(); stateConfig.setJson(true); stateConfig.setPath(ctx.getFilesDir().getAbsolutePath() + "/agentStates/"); stateConfig.setId("conferenceAgent"); config.setState(stateConfig); SimpleSchedulerConfig schedulerConfig = new SimpleSchedulerConfig(); config.setScheduler(schedulerConfig); loadConfig(config); if (!getState().containsKey(CONTACTKEY.getKey())) { getState().put(CONTACTKEY.getKey(), new HashMap<String, Info>()); } DetectionUtil.getInstance().startScan(); getScheduler().schedule(this.getRpc().buildMsg("refresh", null, null), DateTime.now().plus(60000)); reconnect(); }
From source file:org.voidsink.anewjkuapp.utils.AppUtils.java
private static boolean importDefaultPois(Context context) { // import JKU Pois try {// w w w . j a va 2 s. com // write file to sd for import OutputStream mapFileWriter = new BufferedOutputStream( context.openFileOutput(DEFAULT_POI_FILE_NAME, Context.MODE_PRIVATE)); InputStream assetData = new BufferedInputStream(context.getAssets().open(DEFAULT_POI_FILE_NAME)); byte[] buffer = new byte[1024]; int len = assetData.read(buffer); while (len != -1) { mapFileWriter.write(buffer, 0, len); len = assetData.read(buffer); } mapFileWriter.close(); // import file return executeEm(context, new Callable<?>[] { new ImportPoiTask(context, new File(context.getFilesDir(), DEFAULT_POI_FILE_NAME), true) }, false); } catch (IOException e) { Analytics.sendException(context, e, false); return false; } }