Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.net.Uri;
import android.os.Environment;

import java.io.File;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static Uri createUri(String foldername) {
        String storageState = Environment.getExternalStorageState();
        if (storageState.equals(Environment.MEDIA_MOUNTED)) {
            final File root = new File(
                    Environment.getExternalStorageDirectory() + File.separator + foldername + File.separator);
            root.mkdirs();
            final String fname = getUniqueImageFilename(foldername);
            final File sdImageMainDirectory = new File(root, fname);
            return Uri.fromFile(sdImageMainDirectory);
        }
        return null;
    }

    public static String getUniqueImageFilename(String prefix) {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = prefix + timeStamp + ".jpg";
        return imageFileName;
    }
}