Example usage for android.os Environment DIRECTORY_DCIM

List of usage examples for android.os Environment DIRECTORY_DCIM

Introduction

In this page you can find the example usage for android.os Environment DIRECTORY_DCIM.

Prototype

String DIRECTORY_DCIM

To view the source code for android.os Environment DIRECTORY_DCIM.

Click Source Link

Document

The traditional location for pictures and videos when mounting the device as a camera.

Usage

From source file:com.yanzhenjie.album.fragment.BasicCameraFragment.java

/**
 * A random name for the image path.//ww w.  ja v  a2s .co m
 *
 * @return image path for jpg.
 */
protected String randomJPGPath() {
    String outFileFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
            .getAbsolutePath();
    int index = new Random().nextInt(1000);
    String outFilePath = AlbumUtils.getNowDateTime("yyyyMMdd_HHmmssSSS") + "_" + index + ".jpg";
    File file = new File(outFileFolder, outFilePath);
    return file.getAbsolutePath();
}

From source file:com.royclarkson.springagram.PhotoAddFragment.java

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    File image = File.createTempFile(imageFileName, ".jpg", storageDir);
    this.photoPath = image.getAbsolutePath();
    if (Log.isLoggable(TAG, Log.INFO)) {
        Log.i(TAG, "PhotoPath: " + this.photoPath);
    }/*from www. j  a v  a2  s  .  co  m*/
    return image;
}

From source file:org.awesomeapp.messenger.ui.GalleryActivity.java

void startPhotoTaker() {

    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);

    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {

            View view = findViewById(R.id.gallery_fragment);

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            Snackbar.make(view, R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {/*from  w  w  w . j a v a  2s  .co m*/

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA },
                    MY_PERMISSIONS_REQUEST_CAMERA);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {
        // create Intent to take a picture and return control to the calling application
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
                "cs_" + new Date().getTime() + ".jpg");
        mLastPhoto = Uri.fromFile(photo);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mLastPhoto);

        // start the image capture Intent
        startActivityForResult(intent, ConversationDetailActivity.REQUEST_TAKE_PICTURE);
    }
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    fragmentstack = new Stack<Fragment>();
    // creating connection detector class instance
    cd = new ConnectionDetector(MainActivity.this);
    rl_buttons = (RelativeLayout) findViewById(R.id.relative_layout_buttons);
    relativeprogress = (RelativeLayout) findViewById(R.id.relativelayoutprogressbarheader);
    news = (ImageView) findViewById(R.id.button_news);
    deals = (ImageView) findViewById(R.id.button_deals);
    tools = (ImageView) findViewById(R.id.button_tools);
    inventory = (ImageView) findViewById(R.id.button_inventroy);
    info = (ImageView) findViewById(R.id.button_information);
    service = (ImageView) findViewById(R.id.button_services);
    facebook = (Button) findViewById(R.id.button_facebook);
    twitter = (Button) findViewById(R.id.button_twitter);
    google = (Button) findViewById(R.id.button_google);
    digg = (Button) findViewById(R.id.button_digg);
    youtube = (Button) findViewById(R.id.button_youtube);

    java.io.File imageFile1 = new File(
            (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/."
                    + Constants.APPNAME + ""));
    imageFile1.mkdirs();//from  w  ww  .j a  va  2s .c  om
    User user = User.getUser();
    if (user != null) {
        if (GeneralHelper.getInstance(MainActivity.this).isIscheck() == true
                || GeneralHelper.getInstance(MainActivity.this).isIscheckdonetime() == true) {

            //            openfragment();
            //            GeneralHelper.getInstance(com.awrtechnologies.carbudgetsales.MainActivity.this).setIscheckfragment(false);
            loadData();

        } else if (GeneralHelper.getInstance(MainActivity.this).isIscheck() == false
                || GeneralHelper.getInstance(MainActivity.this).isIscheckdonetime() == false) {

            loadData();
        }
    } else {
        //             openNewFragment(new ServiceFragment());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
        ft.replace(R.id.contanier, new Signin_fragment());

        ft.commit();
    }

    deals.setOnClickListener(this);
    inventory.setOnClickListener(this);
    news.setOnClickListener(this);
    tools.setOnClickListener(this);
    info.setOnClickListener(this);
    service.setOnClickListener(this);
    facebook.setOnClickListener(this);
    twitter.setOnClickListener(this);
    google.setOnClickListener(this);
    digg.setOnClickListener(this);
    youtube.setOnClickListener(this);
}

From source file:com.longle1.facedetection.MainActivity.java

public FaceDetect(MainActivity context) throws IOException {
    super(context);

    // Create a private directory and file
    File classifierFile = new File(context.getDir("cascade", Context.MODE_PRIVATE),
            "haarcascade_frontalface_alt.xml");
    FileOutputStream os = new FileOutputStream(classifierFile);
    // load cascade file from application resources
    InputStream is = getResources().openRawResource(R.raw.haarcascade_frontalface_alt);
    // copy from is to os
    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);/* w w  w.j  a  v a  2  s .c o  m*/
    }
    is.close();
    os.close();

    if (classifierFile == null || classifierFile.length() <= 0) {
        throw new IOException("Could not extract the classifier file from Java resource.");
    }

    // Preload the opencv_objdetect module to work around a known bug.
    Loader.load(opencv_objdetect.class);
    classifier = new CvHaarClassifierCascade(cvLoad(classifierFile.getAbsolutePath()));
    classifierFile.delete();
    if (classifier.isNull()) {
        throw new IOException("Could not load the classifier file.");
    }
    storage = CvMemStorage.create();

    // Preload the module to work around a known bug in FFmpegFrameRecorder
    Loader.load(swresample.class);

    // Create looper for asyncHttp
    HandlerThread thread2 = new HandlerThread("AsyncHttpResponseHandler",
            android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mAsyncHttpLooper = thread2.getLooper();
    thread2.start();

    // temp video file
    File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    filePath = folder.getAbsolutePath() + "/Camera/" + "tmp" + ".mp4";

    // Create location
    mLocationData = new LocationData(getContext());
}

From source file:cn.xcom.helper.activity.AuthorizedActivity.java

private void showPickDialog() {
    new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)
            .setNegativeButton("", new DialogInterface.OnClickListener() {
                @Override//from  w w  w.j  ava2 s . co  m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Intent albumIntent = new Intent();
                    albumIntent.setType("image/*");
                    albumIntent.setAction(Intent.ACTION_PICK);
                    startActivityForResult(albumIntent, PHOTO_REQUEST_ALBUM);
                }
            }).setPositiveButton("?", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    int permissionCheck = ContextCompat.checkSelfPermission(mContext,
                            Manifest.permission.CAMERA);
                    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
                        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        String state = Environment.getExternalStorageState();
                        if (state.equals(Environment.MEDIA_MOUNTED)) {
                            File path = Environment
                                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                            File file = new File(path, "51helper.jpg");
                            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                        }
                        startActivityForResult(cameraIntent, PHOTO_REQUEST_CAMERA);
                    } else if (permissionCheck == PackageManager.PERMISSION_DENIED) {
                        // Should we show an explanation?
                        if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext,
                                Manifest.permission.CAMERA)) {

                            // Show an expanation to the user *asynchronously* -- don't block
                            // this thread waiting for the user's response! After the user
                            // sees the explanation, try again to request the permission.

                        } else {

                            // No explanation needed, we can request the permission.

                            ActivityCompat.requestPermissions((Activity) mContext,
                                    new String[] { Manifest.permission.CAMERA },
                                    MY_PERMISSIONS_REQUEST_READ_CONTACTS);

                            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
                            // app-defined int constant. The callback method gets the
                            // result of the request.
                        }
                    }

                }
            }).show();
}

From source file:com.anhubo.anhubo.ui.activity.unitDetial.UploadingActivity1.java

private void takePhoto() {
    //?? ??/*from  w  ww .ja va  2  s .  c  om*/
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    Date date = new Date(System.currentTimeMillis());
    String filename = format.format(date);
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    File outputImage = new File(path, filename + ".jpg");
    try {
        if (outputImage.exists()) {
            outputImage.delete();
        }
        outputImage.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //File?Uri??
    if (Build.VERSION.SDK_INT < 24) {

        imageUri = Uri.fromFile(outputImage);
    } else {
        imageUri = FileProvider.getUriForFile(mActivity, "com.luoli.cameraalbumtest.fileprovider", outputImage);
    }
    Intent tTntent = new Intent("android.media.action.IMAGE_CAPTURE"); //
    tTntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); //?
    startActivityForResult(tTntent, CAMERA); //?

}

From source file:com.microsoft.rightsmanagement.sampleapp.App.java

@Override
public void onCreate() {
    sInstance = this;
    DECLARED_CLASS = this.getClass();
    mStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
}

From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java

private String getDirectoryName(String name) {
    switch (name) {
    case "ALARMS":
        return Environment.DIRECTORY_ALARMS;
    case "DCIM":
        return Environment.DIRECTORY_DCIM;
    case "DOCUMENTS":
        return Environment.DIRECTORY_DOCUMENTS;
    case "DOWNLOADS":
        return Environment.DIRECTORY_DOWNLOADS;
    case "MOVIES":
        return Environment.DIRECTORY_MOVIES;
    case "MUSIC":
        return Environment.DIRECTORY_MUSIC;
    case "NOTIFICATIONS":
        return Environment.DIRECTORY_NOTIFICATIONS;
    case "PICTURES":
        return Environment.DIRECTORY_PICTURES;
    case "PODCASTS":
        return Environment.DIRECTORY_PODCASTS;
    case "RINGTONES":
        return Environment.DIRECTORY_RINGTONES;
    default://from w  w  w.  ja  v  a  2 s. co  m
        throw new IllegalArgumentException("Invalid directory representation: " + name);
    }
}

From source file:link.kjr.file_manager.MainActivity.java

public void clickDCIM(View view) {
    String path = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)).getAbsolutePath();
    setDirectoryView(path);
}