List of usage examples for android.content Context getExternalFilesDir
@Nullable public abstract File getExternalFilesDir(@Nullable String type);
From source file:most.voip.api.Utils.java
/** * Copy the specified resource file from the assets folder into the "files dir" of this application, so that this resource * can be opened by the Voip Lib by providing it the absolute path of the copied resource * @param ctx The application context/* w ww . j a v a2 s.c om*/ * @param assetPath The path of the resource (e.g on_hold.wav or sounds/on_hold.wav) * @return the absolute path of the copied resource, or null if no file was copied. */ public static String getResourcePathByAssetCopy(Context ctx, String assetSubFolder, String fileToCopy) { Log.d(TAG, "getResourcePathByAssetCopy on folder *" + assetSubFolder + "* for file:" + fileToCopy); AssetManager assetManager = ctx.getAssets(); String[] files = null; String filename = null; try { files = assetManager.list(assetSubFolder); Log.d(TAG, "Found " + files.length + " files"); if (files.length > 0) { for (String f : files) { Log.d(TAG, "Found resource:" + f); if (f == null) continue; if (f.equals(fileToCopy)) { filename = f; break; } } Log.d(TAG, "Found:" + filename); if (filename == null) return null; InputStream in = null; OutputStream out = null; try { in = assetManager.open(filename); File outFile = new File(ctx.getExternalFilesDir(null), filename); Log.d(TAG, "Copying asset to " + outFile.getAbsolutePath()); out = new FileOutputStream(outFile); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; return outFile.getAbsolutePath(); } catch (IOException e) { Log.e(TAG, "Failed to copy asset file: " + filename, e); } } } catch (IOException e) { Log.e(TAG, "Failed to get asset file list.", e); } return null; }
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"; }/*from w ww.j a v a 2 s . c o m*/ 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: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 {/*from w w w . j ava 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:com.galactogolf.genericobjectmodel.levelloader.LevelSet.java
public void saveToExternalStorage(Context context) throws LevelSavingException { File filesDir = context.getExternalFilesDir(null); File f = new File(filesDir, this.getFilename()); this.saveToFile(f); }
From source file:com.online.fullsail.SaveWebMedia.java
SaveWebMedia(Context context) { this.context = context; mNM = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { externalData = context.getExternalFilesDir(null); } else {//ww w .j a v a 2s. co m externalData = new File(Environment.getExternalStorageDirectory(), "/FullSailMobile"); if (!externalData.mkdirs()) { externalData.mkdirs(); } } }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private Observable<File> createIfNotExists() { return Observable.just(toImageFileName()).flatMap(fileName -> { if (view.isAvailable()) { try { final Context context = view.getContext(); File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File temp = new File(storageDir, fileName + FILE_EXTENSION); boolean success = temp.createNewFile(); if (success) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp created", temp.getName())); }/*w w w . java 2s .c o m*/ return Observable.just(temp); } catch (IOException ioError) { throw new AndroidException(ioError); } } return Observable.empty(); }); }
From source file:org.jorge.lolin1.func.champs.ChampionManager.java
public void setChampions(Context context) { final String realm = LoLin1Utils.getRealm(context), locale = LoLin1Utils.getLocale(context), pathSeparator = LoLin1Utils.getString(context, "symbol_path_separator", null); String prefName = "pref_version_" + realm + "_" + LoLin1Utils.getLocale(context); logString("debug", "Preference name: " + prefName); File targetFile = new File( context.getExternalFilesDir(LoLin1Utils.getString(context, "content_folder_name", null)) + pathSeparator + realm + LoLin1Utils.getString(context, "symbol_hyphen", null) + PreferenceManager.getDefaultSharedPreferences(context).getString(prefName, "0") + pathSeparator + locale + pathSeparator + LoLin1Utils.getString(context, "list_file_name", null)); try {/* w w w .j a va 2 s . c om*/ logString("targetFile", targetFile.getAbsolutePath()); champions = buildChampions(JsonManager.getStringAttribute(FileManager.readFileAsString(targetFile), LoLin1Utils.getString(context, "champion_list_key", null))); } catch (IOException e) { //It's fine, nothing will get shown champions = new ArrayList<>(); } }
From source file:com.sap.nwcloudmanager.api.LogAPI.java
public static void downloadLog(final Context context, final String appId, final String logName, final DownloadLogResponseHandler downloadLogResponseHandler) { NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance(); getHttpClient().setBasicAuth(config.getUsername(), config.getPassword()); String[] contentTypes = { "application/x-gzip" }; getHttpClient().get("https://monitoring." + config.getHost() + "/log/api_basic/logs/" + config.getAccount() + "/" + appId + "/web/" + logName, null, new BinaryHttpResponseHandler(contentTypes) { /*/*from ww w. j a v a 2s .co m*/ * (non-Javadoc) * * @see * com.loopj.android.http.BinaryHttpResponseHandler#onSuccess(byte * []) */ @Override public void onSuccess(byte[] arg0) { GZIPInputStream gzis = null; try { gzis = new GZIPInputStream(new ByteArrayInputStream(arg0)); StringBuilder string = new StringBuilder(); byte[] data = new byte[4028]; int bytesRead; while ((bytesRead = gzis.read(data)) != -1) { string.append(new String(data, 0, bytesRead)); } File downloadsFile = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); if (downloadsFile.exists()) { downloadsFile = new File( context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath() + "/" + logName); FileOutputStream fos = new FileOutputStream(downloadsFile); fos.write(string.toString().getBytes()); fos.close(); } downloadLogResponseHandler.onSuccess(downloadsFile.getAbsolutePath()); } catch (IOException e) { Log.e(e.getMessage()); } finally { try { if (gzis != null) { gzis.close(); } } catch (IOException e) { } } } @Override public void onFailure(Throwable arg0) { downloadLogResponseHandler.onFailure(arg0, arg0.getMessage()); } }); }
From source file:com.rareventure.gps2.GTG.java
public static boolean requireSdcardPresent(Context context) { if (Requirement.SDCARD_PRESENT.isFulfilledAndAssertPriorRequirements()) return true; externalFilesDir = context.getExternalFilesDir(null); if (!sdCardMounted(context)) { return false; }// w w w . j a va 2 s . c o m Requirement.SDCARD_PRESENT.fulfill(); return true; }
From source file:com.example.anna_maria.myapplication.Camera2VideoFragment.java
private File getVideoFile(Context context) { return new File(context.getExternalFilesDir(null), "video.mp4"); }