List of usage examples for android.os Environment DIRECTORY_DCIM
String DIRECTORY_DCIM
To view the source code for android.os Environment DIRECTORY_DCIM.
Click Source Link
From source file:info.shibafu528.gallerymultipicker.MultiPickerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); int id = item.getItemId(); if (id == android.R.id.home) { if (getSupportFragmentManager().getBackStackEntryCount() > 0) { getSupportFragmentManager().popBackStack(); } else {/*from ww w . j a v a 2 s . co m*/ setResult(RESULT_CANCELED); finish(); } } else if (id == R.id.info_shibafu528_gallerymultipicker_action_decide) { accept(getSelectedUris()); } else if (id == R.id.info_shibafu528_gallerymultipicker_action_gallery) { Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_PICK : Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, REQUEST_GALLERY); } else if (id == R.id.info_shibafu528_gallerymultipicker_action_take_a_photo) { boolean existExternal = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (!existExternal) { Toast.makeText(this, R.string.info_shibafu528_gallerymultipicker_storage_error, Toast.LENGTH_SHORT) .show(); return true; } else { File extDestDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), mCameraDestDir != null ? mCameraDestDir : "Camera"); if (!extDestDir.exists()) { extDestDir.mkdirs(); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String fileName = sdf.format(new Date(System.currentTimeMillis())); File destFile = new File(extDestDir.getPath(), fileName + ".jpg"); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.DATA, destFile.getPath()); mCameraTemp = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraTemp); startActivityForResult(intent, REQUEST_CAMERA); } } return true; }
From source file:com.awrtechnologies.carbudgetsales.MainActivity.java
public void imageOpen(Fragment f, final int REQUEST_CAMERA, final int SELECT_FILE) { GeneralHelper.getInstance(MainActivity.this).setTempFragment(f); final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Add Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override/*from w w w. j a va 2s . c o m*/ public void onClick(DialogInterface dialog, int item) { if (items[item].equals("Take Photo")) { java.io.File imageFile = new File( (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/." + Constants.APPNAME + "/" + System.currentTimeMillis() + ".jpeg")); PreferencesManager.setPreferenceByKey(MainActivity.this, "IMAGEWWC", imageFile.getAbsolutePath()); // imageFilePath = imageFile; imageFileUri = Uri.fromFile(imageFile); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri); startActivityForResult(i, REQUEST_CAMERA); } else if (items[item].equals("Choose from Library")) { if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } } else if (items[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
From source file:com.microsoft.mimickeralarm.ringing.ShareFragment.java
public void download() { File cameraDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File sourceFile = new File(mShareableUri); String dateTimeString = (new SimpleDateFormat("yyyy-MM-dd-HHmmss").format(new Date())); // Example: 2015-12-31-193205 String targetFileName = MIMICKER_FILE_PREFIX + dateTimeString + ".jpg"; // "Mimicker_2015-12-31-193205.jpg File targetFile = new File(cameraDirectory.getPath(), targetFileName); try {/*from www . j a v a2 s .c o m*/ copyFile(sourceFile, targetFile); } catch (IOException ex) { showToastInFragment(R.string.share_download_failure); Logger.trackException(ex); return; } // Inform the media store about the new file ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.MediaColumns.DATA, targetFile.getPath()); getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); showToastInFragment(R.string.share_download_success); }
From source file:com.qsoft.components.gallery.utils.GalleryUtils.java
public static File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "Camera"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("Camera", "failed to create directory"); return null; }/*from w w w .jav a 2 s .c om*/ } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".png"); } else if (type == MEDIA_TYPE_VIDEO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4"); } else { return null; } return mediaFile; }
From source file:com.anhubo.anhubo.ui.activity.unitDetial.UploadingActivity1.java
/** * ?? ?????//from w ww .j av a2 s. co m **/ private File savePicture(Bitmap bitmap, String fileName) { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File outputImage = new File(path, fileName + ".jpg"); try { if (outputImage.exists()) { outputImage.delete(); } outputImage.createNewFile(); OutputStream stream = new FileOutputStream(outputImage); bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream);// } catch (Exception e) { e.printStackTrace(); } finally { } return outputImage; }
From source file:cn.xcom.helper.activity.AuthorizedActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_CANCELED) { switch (requestCode) { case PHOTO_REQUEST_CAMERA:// // ???? String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File tempFile = new File(path, "51helper.jpg"); startPhotoZoom(Uri.fromFile(tempFile)); } else { Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show(); }//w w w . j a va 2 s . c om break; case PHOTO_REQUEST_ALBUM:// startPhotoZoom(data.getData()); break; case PHOTO_REQUEST_CUT: // ?? if (data != null) { getImageToView(data); } break; case 4: if (data != null) { tv_city.setText(data.getStringExtra("city")); } } } super.onActivityResult(requestCode, resultCode, data); }
From source file:net.nanocosmos.bintu.demo.encoder.activities.StreamActivity.java
private nanoStreamSettings configureNanostreamSettings() { if (recordMp4) { try {//w w w . j a va 2 s . c om // get the external DCIM Folder for mp4 recording. // for a docu about mp4 recording see http://www.nanocosmos.de/v4/documentation/android_mp4_recording File _path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File subDir = new File(_path, "BintuStreamer"); boolean result = true; if (!subDir.exists()) { result = subDir.mkdirs(); } if (result) { File filePath = new File(subDir, "Test.mp4"); int i = 1; while (filePath.exists()) { filePath = new File(subDir, "Test_" + i + ".mp4"); i++; } mp4FilePath = filePath.getAbsolutePath(); } else { recordMp4 = false; } } catch (Exception e) { recordMp4 = false; Logging.log(Logging.LogLevel.ERROR, TAG, "Failed to get video path. ", e); } } // new AdaptiveBitrateControlSettings(mode) creates a default AdaptiveBitrateControlSettings object // with the following values: // adaptive bitrate control mode = mode (DISABLE, QUALITY_DEGRADE, FRAME_DROP, QUALITY_DEGRADE_AND_FRAME_DROP) // min bit rate = 50k // max bit rate = 2M // flush Buffer Threshold = 50% // min frame rate = 5 abcSettings = new AdaptiveBitrateControlSettings(abcMode); abcSettings.SetMaximumBitrate((int) (videoBitrate * 1.5)); // new LogSettings() creates a default LogSettings object with the following values: // log path = own directory (e.g. /sdcard/Android/com.example.appname/files/) // log name = RTMPStream.log // Log level = LogLevel.ERROR // log enabled = 1 String dir = new String("logs"); File f = new File(getExternalFilesDir(dir), ""); String path = f.getAbsolutePath(); logSettings = new Logging.LogSettings(path, "nanoStreamRTMP.log", Logging.LogLevel.VERBOSE, 1); // new VideoSettings() creates a default VideoSettings object with the following values: // video resolution = 640x480 // video bit rate = 500k // video frame rate = 15 // key frame interval = 5 // video source type = VideoSourceType.INTERNAL_BACK // use auto focus = true // use torch = false // aspect ratio = AspectRatio.RATIO_KEEP_INPUT VideoSettings vs = new VideoSettings(); vs.setBitrate(videoBitrate); vs.setFrameRate(videoFramerate); vs.setResolution(videoResolution); vs.setVideoSourceType(videoSourceType); vs.setAspectRatio(videoAspectRatio); vs.setKeyFrameInterval(videoKeyFrameInterval); vs.setUseAutoFocus(useAutoFocus); vs.setUseTorch(useTorch); // new AudioSettings() creates a default AudioSettings object with the following values: // audio channels = 2 // audio bit rate = 64k // audio sample rate = 44.1k AudioSettings as = new AudioSettings(); as.setBitrate(audioBitrate); as.setChannels(audioChannels); as.setSamplerate(audioSamplerate); // new nanoStreamSettings() creates a default nanoStreamSettings object with the following values: // has video = true // video settings = default video settings // has audio = true // audio settings = default audio settings // preview holder = null // license = "" // stream url = "" // stream name = "" // event listener = null // Adaptive Bit rate settings = disabled // log settings = default log settings // send rtmp = true // record MP4 = false // mp4 path = "" // you need to set at least the license, stream url and the stream name to be able to start a stream. nanoStreamSettings nss = new nanoStreamSettings(); nss.setVideoSettings(vs); nss.setHaveVideo(streamVideo); nss.setPreviewSurface(surface); nss.setAudioSettings(as); nss.setHaveAudio(streamAudio); nss.setAbcSettings(abcSettings); nss.setLogSettings(logSettings); nss.setLicense(Configuration.NANOSTREAM_LICENSE); nss.setStreamUrl(serverUrl); nss.setStreamName(streamName); nss.setAuthUser(authUser); nss.setAuthPassword(authPassword); nss.setSendRtmp(sendRtmp); nss.setEventListener(this); nss.setMp4Path(mp4FilePath); nss.setRecordMp4(recordMp4); return nss; }
From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.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)) { // 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(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show(); } else {//ww w .j a v a 2 s .com // 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:chinanurse.cn.nurse.Fragment_Nurse_job.IdentityFragment_ACTIVITY.java
protected void ShowPickDialog() { new AlertDialog.Builder(activity, AlertDialog.THEME_HOLO_LIGHT) .setNegativeButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss();/*from w w w. j a va2s . co m*/ Intent intentFromGallery = new Intent(); intentFromGallery.setType("image/*"); // intentFromGallery.setAction(Intent.ACTION_PICK); startActivityForResult(intentFromGallery, PHOTO_REQUEST_ALBUM); } }).setPositiveButton("?", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); Intent intentFromCapture = 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, "newpic.jpg"); intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); } startActivityForResult(intentFromCapture, PHOTO_REQUEST_CAMERA); } }).show(); }
From source file:fpt.isc.nshreport.utilities.FileUtils.java
public static Uri createImageFile(Context context) throws IOException { // Create an image file name /*String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_";*/ String imageFileName = "JPEG_NSH.jpg"; File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "Camera"); /*File image = File.createTempFile( imageFileName, *//* prefix *//* ".jpg", *//* suffix *//* storageDir *//* directory *//* );*/ File image = new File(storageDir, imageFileName); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); Uri photoURI = FileProvider.getUriForFile(context, "fpt.isc.nshreport.provider", image); return photoURI; }