get String Uri From Camera Result - Android Camera

Android examples for Camera:Camera Attribute

Description

get String Uri From Camera Result

Demo Code


//package com.java2s;
import java.io.File;
import java.io.FileNotFoundException;
import android.app.Activity;

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

public class Main {
    private static String getStringUriFromCameraResult(Activity activity) {
        Uri uri = null;/*from w ww.  jav  a2s.c o  m*/
        File file = getFileToStoreCameraResult();
        try {
            uri = Uri.parse(android.provider.MediaStore.Images.Media
                    .insertImage(activity.getContentResolver(),
                            file.getAbsolutePath(), null, null));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        if (uri != null) {
            return uri.toString();
        }
        return null;
    }

    public static File getFileToStoreCameraResult() {
        String directoryPath = Environment.getExternalStorageDirectory()
                + "/data/com.raulete.evoluzzion/tmp/";
        File directory = new File(directoryPath);
        if (!directory.exists())
            directory.mkdirs();
        String filePath = directoryPath + "camera_capture";
        File file = new File(filePath);
        return file;
    }
}

Related Tutorials