Example usage for android.os Environment getExternalStoragePublicDirectory

List of usage examples for android.os Environment getExternalStoragePublicDirectory

Introduction

In this page you can find the example usage for android.os Environment getExternalStoragePublicDirectory.

Prototype

public static File getExternalStoragePublicDirectory(String type) 

Source Link

Document

Get a top-level shared/external storage directory for placing files of a particular type.

Usage

From source file:com.yanzhenjie.album.fragment.BasicCameraFragment.java

/**
 * A random name for the image path./*  w  w w.  j a  va  2 s .c  o m*/
 *
 * @return image path for jpg.
 */
protected String randomJPGPath() {
    String outFileFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
            .getAbsolutePath();
    int index = new Random().nextInt(1000);
    String outFilePath = AlbumUtils.getNowDateTime("yyyyMMdd_HHmmssSSS") + "_" + index + ".jpg";
    File file = new File(outFileFolder, outFilePath);
    return file.getAbsolutePath();
}

From source file:de.yaacc.util.FileDownloader.java

@Override
protected Void doInBackground(DIDLObject... didlObjects) {
    if (didlObjects == null || didlObjects.length == 0 || didlObjects.length > 1) {
        throw new IllegalStateException("to less or many didlObjects....");
    }//ww w.j  a v a 2  s . co  m
    if (!isExternalStorageWritable()) {
        throw new IllegalStateException("External Storage is not writeable");
    }

    try {
        File storageDir = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/yaacc");
        if (!storageDir.exists()) {
            storageDir.mkdir();
        }
        createNotification(storageDir.getAbsolutePath());
        List<Item> items = upnpClient.toItemList(didlObjects[0]);
        for (Item item : items) {
            PlayableItem playableItem = new PlayableItem(item, 0);
            String filename = playableItem.getTitle().replace(" ", "");
            filename += "." + MimeTypeMap.getSingleton().getExtensionFromMimeType(playableItem.getMimeType());
            File file = new File(storageDir, filename);
            if (file.exists()) {
                int i = 1;
                while (file.exists()) {
                    filename = playableItem.getTitle().replace(" ", "") + "_" + i;
                    filename += "."
                            + MimeTypeMap.getSingleton().getExtensionFromMimeType(playableItem.getMimeType());
                    file = new File(storageDir, filename);
                    i++;
                }
            }

            try {

                InputStream is = new URL(playableItem.getUri().toString()).openStream();
                FileOutputStream outputStream = new FileOutputStream(file);
                byte[] b = new byte[1024];
                int len = 0;
                while ((len = is.read(b)) != -1) {
                    outputStream.write(b, 0, len);
                }
                is.close();
                outputStream.close();

            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    } finally {
        cancleNotification();
    }
    return null;
}

From source file:com.cyberocw.habittodosecretary.file.StorageHelper.java

public static String getStorageDir() {
    // return Environment.getExternalStorageDirectory() + File.separator +
    // Const.ERROR_TAG + File.separator;
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
}

From source file:butter.droid.base.fragments.dialog.FileSelectorDialogFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_dialog_fileselector, container);
    list = (ListView) view.findViewById(android.R.id.list);

    currentDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    fill(currentDir);//from w w w  .ja va  2  s .  c  o  m

    return view;
}

From source file:com.foreignreader.WordListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (BooksActivity.TESTING_STORGE)
        ObjectsFactory.storageFile = new File(getFilesDir(), "words.db");
    else {/*www.  ja v a2 s.  c o  m*/
        File file = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getParentFile(),
                "Foreign Reader");
        file.mkdirs();
        ObjectsFactory.storageFile = new File(file, "words.db");
    }

    setContentView(R.layout.activity_word_list);

    if (BooksActivity.TESTING_STORGE)
        ObjectsFactory.storageFile = new File(getFilesDir(), "words.db");
    else {
        File file = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getParentFile(),
                "Foreign Reader");
        file.mkdirs();
        ObjectsFactory.storageFile = new File(file, "words.db");
    }

    int[] n = ObjectsFactory.getDefaultDatabase().getWordsCount();

    if (findViewById(R.id.word_detail_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;

        TextView stat = (TextView) findViewById(R.id.statisticTextView);
        stat.setText("Known words: " + n[0] + "   Unknown words: " + n[1]);

        // In two-pane mode, list items should be given the
        // 'activated' state when touched.
        ((WordListFragment) getSupportFragmentManager().findFragmentById(R.id.word_list))
                .setActivateOnItemClick(true);
    }

}

From source file:org.disrupted.rumble.util.FileUtil.java

public static File getReadableAlbumStorageDir() throws IOException {
    if (!isExternalStorageReadable())
        throw new IOException("Storage is not readable");

    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            RUMBLE_IMAGE_ALBUM_NAME);//from  www  .  j a  v  a2  s .c om
    if (!file.mkdirs()) {
    }

    return file;
}

From source file:de.qspool.clementineremote.ui.settings.DefaultDirChooser.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private LinkedList<String> getDirectories() {
    LinkedList<String> directories = new LinkedList<>();

    File[] defaultDirs = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_MUSIC);
    for (File f : defaultDirs) {
        if (f != null)
            directories.add(f.toString());
    }/*w ww  .  j a v a 2 s .  c o m*/

    String publicMusicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
            .toString();
    if (canWriteToExternalStorage(publicMusicDir)) {
        directories.add(publicMusicDir);
    }

    if (canWriteToExternalStorage(Environment.getExternalStorageDirectory().getAbsolutePath())) {
        directories.add(mContext.getString(R.string.file_dialog_custom_paths_available));
    }
    return directories;
}

From source file:com.qasp.diego.arsp.Atualiza.java

private static InputStream getArquivodeDados() throws IOException {

    final String NOME = "data.dat";
    File arquivo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            NOME);/* www . ja v  a 2 s.  c o  m*/
    return (new FileInputStream(arquivo));
}

From source file:org.apache.cordova.plugin.AMImageDownloader.java

private void savePhoto(Bitmap bmp) {
    OutputStream fOut = null;/*from  www  .  j av  a2s . c om*/
    Calendar c = Calendar.getInstance();
    String date = String.valueOf((c.get(Calendar.MONTH))) + String.valueOf((c.get(Calendar.DAY_OF_MONTH)))
            + String.valueOf((c.get(Calendar.YEAR))) + String.valueOf((c.get(Calendar.HOUR_OF_DAY)))
            + String.valueOf((c.get(Calendar.MINUTE))) + String.valueOf((c.get(Calendar.SECOND)));

    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            date.toString() + ".png");
    try {
        fOut = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        fOut.flush();
        fOut.close();

        /**Update image to gallery**/
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        Uri contentUri = Uri.fromFile(file);
        mediaScanIntent.setData(contentUri);
        this.cordova.getActivity().sendBroadcast(mediaScanIntent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ufms.br.com.ufmsapp.task.DownloadTask.java

private void buildNotification() {
    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    builder = new NotificationCompat.Builder(context);

    builder.setSmallIcon(iconResId);/*from   w ww  .j a v  a  2 s .  c  o  m*/
    builder.setContentTitle(fileName);
    builder.setContentText(msg);

    builder.setAutoCancel(true);

    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            fileName);
    intent.setDataAndType(Uri.fromFile(file),
            GetFileMimeType.getMimeType(title.replace(UPLOAD_PATH_REPLACE, "")));

    piOpenNotification = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(piOpenNotification);

    builder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
}