get Output Media File by media type - Android Media

Android examples for Media:Media File

Description

get Output Media File by media type

Demo Code


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

public class Main {
    public static Uri getOutputMediaFile(int type) {
        File outputLocation = new File(
                Environment/*from   ww  w  . j av a  2  s .  com*/
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "Mixology");

        if (!outputLocation.exists()) {
            if (!outputLocation.mkdirs()) {
                Log.d("Camera", "Couldn't make output directory");
            }
        }

        String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
        File outputFile;
        if (type == 1) {
            outputFile = new File(outputLocation.getPath() + File.separator
                    + "IMG_" + timestamp + ".jpg");
        } else {
            return null;
        }

        return Uri.fromFile(outputFile);
    }
}

Related Tutorials