Code example for File

Methods: fromFile

0
         
        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
         
        String mediaCapturePath = path + File.separator + "Camera" + File.separator + "wp-" + System.currentTimeMillis() + ".jpg";
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mediaCapturePath)));
 
        if (callback != null) {
            callback.onMediaCapturePathReady(mediaCapturePath);
        } 
         
        // make sure the directory we plan to store the recording in exists 
        File directory = new File(mediaCapturePath).getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
            try { 
                throw new IOException("Path to file could not be created.");
            } catch (IOException e) {
                e.printStackTrace();
            } 
        } 
        return intent;