Android SDCard Root Get getOutputMediaFileUri()

Here you can find the source of getOutputMediaFileUri()

Description

get Output Media File Uri

Declaration

public static Uri getOutputMediaFileUri() 

Method Source Code

//package com.java2s;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static Uri getOutputMediaFileUri() {
        File mediaStorageDir = new File(
                Environment// ww  w.  ja  v  a  2 s .  co m
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "MyCameraApp");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("MyCameraApp", "failed to create directory");
                return null;
            }
        }

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
        File mediaFile = new File(mediaStorageDir.getPath()
                + File.separator + "IMG_" + timeStamp + ".jpg");
        //     L.e(Uri.fromFile(mediaFile).toString());
        return Uri.fromFile(mediaFile);
    }
}

Related

  1. getExternalCacheDir(Context context)
  2. getRootFilePath()
  3. getSDCardRoot()
  4. getOutputMediaFile()
  5. getOutputMediaFile(int type)