Example usage for android.content Context getExternalFilesDir

List of usage examples for android.content Context getExternalFilesDir

Introduction

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

Prototype

@Nullable
public abstract File getExternalFilesDir(@Nullable String type);

Source Link

Document

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns.

Usage

From source file:com.nextgis.mobile.util.SelectMapPathPreference.java

@Override
protected void onClick() {
    super.onClick();

    Context context = getContext();
    File path = context.getExternalFilesDir(null);
    if (null == path) {
        path = context.getFilesDir();/*ww w .j  a v a 2  s. co  m*/
    }

    LocalResourceSelectDialog dialog = new LocalResourceSelectDialog();
    dialog.setPath(path);
    dialog.setTypeMask(ConstantsUI.FILETYPE_FOLDER);
    dialog.setCanSelectMultiple(false);
    dialog.setOnSelectionListener(this);
    dialog.show(mFragmentManager, ConstantsUI.FRAGMENT_SELECT_RESOURCE);
}

From source file:com.filemanager.free.filesystem.FileUtil.java

/**
 * Get a list of external SD card paths. (Kitkat or higher.)
 *
 * @return A list of external SD card paths.
 *//*from   www.jav  a2  s .c  o  m*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String[] getExtSdCardPaths(Context context) {
    List<String> paths = new ArrayList<String>();
    for (File file : context.getExternalFilesDirs("external")) {
        if (file != null && !file.equals(context.getExternalFilesDir("external"))) {
            int index = file.getAbsolutePath().lastIndexOf("/Android/data");
            if (index < 0) {
                Log.w("FileUtils", "Unexpected external file dir: " + file.getAbsolutePath());
            } else {
                String path = file.getAbsolutePath().substring(0, index);
                try {
                    path = new File(path).getCanonicalPath();
                } catch (IOException e) {
                    // Keep non-canonical path.
                }
                paths.add(path);
            }
        }
    }
    if (paths.isEmpty())
        paths.add("/storage/sdcard1");
    return paths.toArray(new String[0]);
}

From source file:org.jorge.lolin1.func.champs.ChampionManager.java

public Bitmap getBustImageByChampion(int width, int height, Champion champion, Context context) {
    File root = context.getExternalFilesDir(LoLin1Utils.getString(context, "content_folder_name", null));
    final String realm = LoLin1Utils.getRealm(context),
            pathSeparator = LoLin1Utils.getString(context, "symbol_path_separator", null);
    final StringBuilder absolutePathToBustBuilder = new StringBuilder(root.getPath()).append(pathSeparator)
            .append(realm).append(LoLin1Utils.getString(context, "symbol_hyphen", null))
            .append(PreferenceManager.getDefaultSharedPreferences(context)
                    .getString("pref_version_" + realm + "_" + LoLin1Utils.getLocale(context), "0"))
            .append(pathSeparator).append(LoLin1Utils.getLocale(context)).append(pathSeparator)
            .append(LoLin1Utils.getString(context, "champion_image_folder", null)).append(pathSeparator);

    absolutePathToBustBuilder.append(LoLin1Utils.getString(context, "bust_image_folder_name", null))
            .append(pathSeparator).append(champion.getBustImageName());

    return bitmapLoader.getBitmapFromCache(absolutePathToBustBuilder.toString(), width, height);
}

From source file:org.jorge.lolin1.func.champs.ChampionManager.java

public Bitmap getPassiveImageByChampion(Champion target, Context context, int width, int height) {
    File root = context.getExternalFilesDir(LoLin1Utils.getString(context, "content_folder_name", null));
    final String realm = LoLin1Utils.getRealm(context),
            pathSeparator = LoLin1Utils.getString(context, "symbol_path_separator", null);

    StringBuilder absolutePathToPassiveBuilder = new StringBuilder(root.getPath()).append(pathSeparator)
            .append(realm).append(LoLin1Utils.getString(context, "symbol_hyphen", null))
            .append(PreferenceManager.getDefaultSharedPreferences(context)
                    .getString("pref_version_" + realm + "_" + LoLin1Utils.getLocale(context), "0"))
            .append(pathSeparator).append(LoLin1Utils.getLocale(context)).append(pathSeparator)
            .append(LoLin1Utils.getString(context, "champion_image_folder", null)).append(pathSeparator);

    absolutePathToPassiveBuilder.append(LoLin1Utils.getString(context, "passive_image_folder_name", null))
            .append(pathSeparator).append(target.getPassive().getImageName());

    return bitmapLoader.getBitmapFromCache(absolutePathToPassiveBuilder.toString(), width, height);
}

From source file:org.jorge.lolin1.func.champs.ChampionManager.java

public Bitmap getSpellImageByChampion(Champion target, Context context, Integer width, Integer height,
        int spellIndex) {
    File root = context.getExternalFilesDir(LoLin1Utils.getString(context, "content_folder_name", null));
    final String realm = LoLin1Utils.getRealm(context),
            pathSeparator = LoLin1Utils.getString(context, "symbol_path_separator", null);

    StringBuilder absolutePathToPassiveBuilder = new StringBuilder(root.getPath()).append(pathSeparator)
            .append(realm).append(LoLin1Utils.getString(context, "symbol_hyphen", null))
            .append(PreferenceManager.getDefaultSharedPreferences(context)
                    .getString("pref_version_" + realm + "_" + LoLin1Utils.getLocale(context), "0"))
            .append(pathSeparator).append(LoLin1Utils.getLocale(context)).append(pathSeparator)
            .append(LoLin1Utils.getString(context, "champion_image_folder", null)).append(pathSeparator);

    absolutePathToPassiveBuilder.append(LoLin1Utils.getString(context, "spell_image_folder_name", null))
            .append(pathSeparator).append(target.getSpells()[spellIndex].getImageName());

    return bitmapLoader.getBitmapFromCache(absolutePathToPassiveBuilder.toString(), width, height);
}

From source file:org.jorge.lolin1.func.champs.ChampionManager.java

public Bitmap getSplashImageByChampion(Champion target, Context context, Integer width, Integer height,
        int splashIndex) {
    File root = context.getExternalFilesDir(LoLin1Utils.getString(context, "content_folder_name", null));
    final String realm = LoLin1Utils.getRealm(context),
            pathSeparator = LoLin1Utils.getString(context, "symbol_path_separator", null);

    StringBuilder absolutePathToPassiveBuilder = new StringBuilder(root.getPath()).append(pathSeparator)
            .append(realm).append(LoLin1Utils.getString(context, "symbol_hyphen", null))
            .append(PreferenceManager.getDefaultSharedPreferences(context)
                    .getString("pref_version_" + realm + "_" + LoLin1Utils.getLocale(context), "0"))
            .append(pathSeparator).append(LoLin1Utils.getLocale(context)).append(pathSeparator)
            .append(LoLin1Utils.getString(context, "champion_image_folder", null)).append(pathSeparator);

    absolutePathToPassiveBuilder.append(LoLin1Utils.getString(context, "splash_image_folder_name", null))
            .append(pathSeparator).append(target.getSimplifiedName() + "_" + splashIndex + "."
                    + LoLin1Utils.getString(context, "splash_image_extension", null));

    return bitmapLoader.getBitmapFromCache(absolutePathToPassiveBuilder.toString(), width, height);
}

From source file:com.grokkingandroid.sampleapp.samples.data.contentprovider.lentitems.LentItemDisplayFragment.java

/**
 * The dummyApplyBatch method is only used to show a sample batch. 
 * It's not used within this sample app.
 *///ww w  . j av  a  2  s  .  c  om
@SuppressWarnings("unused")
private void dummyApplyBatch() {

    String borrower = "John Doe";
    String item = "Anhalter";
    boolean hasPic = true;
    Context ctx = getActivity();
    String somePath = ctx.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath();

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(ContentProviderOperation.newInsert(Items.CONTENT_URI).withValue(Items.NAME, item)
            .withValue(Items.BORROWER, borrower).build());
    if (hasPic) {
        ops.add(ContentProviderOperation.newInsert(Photos.CONTENT_URI).withValue(Photos._DATA, somePath)
                .withValueBackReference(Photos.ITEMS_ID, 0).build());
    }
    try {
        ContentResolver resolver = getActivity().getContentResolver();
        resolver.applyBatch(LentItemsContract.AUTHORITY, ops);
    } catch (OperationApplicationException e) {
        Log.e("wemonit", "cannot apply batch: " + e.getLocalizedMessage(), e);
    } catch (RemoteException e) {
        Log.e("wemonit", "cannot apply batch: " + e.getLocalizedMessage(), e);
    }

    // EventBus.getDefault().post(whatever);

}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static File copyMediaFromUri(Context context, Uri uri) throws IOException {
    InputStream is = null;//from   w  w w . ja  va2s  . c  o  m
    OutputStream os = null;
    try {
        ContentResolver contentResolver = context.getContentResolver();

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "MAGE_" + timeStamp;

        MimeTypeMap mime = MimeTypeMap.getSingleton();
        String extension = "." + mime.getExtensionFromMimeType(contentResolver.getType(uri));

        File directory = context.getExternalFilesDir("media");
        File file = File.createTempFile(imageFileName, /* prefix */
                extension, /* suffix */
                directory /* directory */
        );

        is = contentResolver.openInputStream(uri);
        os = new FileOutputStream(file);
        ByteStreams.copy(is, os);

        return file;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }

        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:hochschuledarmstadt.photostream_tools.ImageCacher.java

private File concatImageFilePath(Context context, String imageFileName) {
    File file = new File(context.getFilesDir(), imageFileName);
    if (!file.exists() && isExternalStorageAccessible()) {
        File pictureDirectory = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        if (!pictureDirectory.exists())
            pictureDirectory.mkdir();//from   w ww. j a v  a 2s. c  o m
        file = new File(pictureDirectory, imageFileName);
    }
    return file;
}

From source file:com.esminis.server.mariadb.server.MariaDbServerLauncher.java

private List<String> createCommandInternal(Context context, File binary, File root) throws IOException {
    final List<String> command = new ArrayList<>();
    final File directoryTemp = new File(context.getExternalFilesDir(null), "temp");
    final File fileSocket = new File(binary.getParentFile(), "mysql.sock");
    if (!directoryTemp.isDirectory() && !directoryTemp.mkdirs()) {
        throw new IOException("Cannot create directory: " + directoryTemp.getAbsolutePath());
    }//from   w w w.jav  a2s. co m
    command.add(binary.getAbsolutePath());
    command.add("--lc-messages-dir=" + new File(binary.getParentFile(), "share"));
    command.add("--tmpdir=" + directoryTemp.getAbsolutePath());
    command.add("--socket=" + fileSocket);
    command.add("--basedir=" + binary.getParentFile().getAbsolutePath());
    command.add("--datadir=" + root.getAbsolutePath());
    command.add("--lower-case-table-names=1");
    return command;
}