Java Code Examples for android.os.Environment#DIRECTORY_PICTURES

The following examples show how to use android.os.Environment#DIRECTORY_PICTURES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilsHandler.java    From PowerFileExplorer with GNU General Public License v3.0 9 votes vote down vote up
public void addCommonBookmarks() {
    String sd = Environment.getExternalStorageDirectory() + "/";

    String[] dirs = new String[] {
            sd + Environment.DIRECTORY_DCIM,
            sd + Environment.DIRECTORY_DOWNLOADS,
            sd + Environment.DIRECTORY_MOVIES,
            sd + Environment.DIRECTORY_MUSIC,
            sd + Environment.DIRECTORY_PICTURES
    };

    for (String dir : dirs) {

        addBookmark(new File(dir).getName(), dir);
    }
}
 
Example 2
Source File: ScopedDirectoryAccessFragment.java    From android-ScopedDirectoryAccess with Apache License 2.0 8 votes vote down vote up
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:
            throw new IllegalArgumentException("Invalid directory representation: " + name);
    }
}
 
Example 3
Source File: FloatingButtonService.java    From WhatsAppStatusSaver with Apache License 2.0 6 votes vote down vote up
private void saveAllSelectedStatus(ArrayList<String> statuses) {
    String fileType = Environment.DIRECTORY_PICTURES;
    for (String status : statuses) {
        if (status.endsWith(".jpg")) {
            fileType = "Pictures";
        } else if (status.endsWith(".gif")) {
            fileType = "Gifs";
        } else if (status.endsWith(".mp4")) {
            fileType = "Videos";
        }
        String[] splitStatus = status.split("/");
        String destinationFilename = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/WhatsAppSaver" + File.separatorChar + splitStatus[splitStatus.length - 1];
        try {
            copyFile(new File(status), new File(destinationFilename));
            Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
            intent.setData(Uri.fromFile(new File(destinationFilename)));
            sendBroadcast(intent);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 4
Source File: RCTCameraModule.java    From react-native-camera-face-detector with MIT License 6 votes vote down vote up
private File getOutputMediaFile(int type) {
    // Get environment directory type id from requested media type.
    String environmentDirectoryType;
    if (type == MEDIA_TYPE_IMAGE) {
        environmentDirectoryType = Environment.DIRECTORY_PICTURES;
    } else if (type == MEDIA_TYPE_VIDEO) {
        environmentDirectoryType = Environment.DIRECTORY_MOVIES;
    } else {
        Log.e(TAG, "Unsupported media type:" + type);
        return null;
    }

    return getOutputFile(
            type,
            Environment.getExternalStoragePublicDirectory(environmentDirectoryType)
    );
}
 
Example 5
Source File: FileUtils.java    From filemanager with MIT License 6 votes vote down vote up
public static boolean isMediaDirectory(File file)
{
	try
	{
		String path = file.getCanonicalPath();
		for (String directory : new String[]{Environment.DIRECTORY_DCIM,
                   Environment.DIRECTORY_MUSIC,
				Environment.DIRECTORY_PICTURES})
		{
			if (path.startsWith(Environment.getExternalStoragePublicDirectory(directory)
					.getAbsolutePath()))
				return true;
		}
		return false;
	} catch (IOException e)
	{
		e.printStackTrace();
		return false;
	}
}
 
Example 6
Source File: PlaybackView.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private void save(File file) {

        if (PermissionHelper.hasStoragePermission(getContext())) {
            String directoryName = Environment.DIRECTORY_PICTURES;
            File picDirectory = Environment.getExternalStoragePublicDirectory(directoryName);

            File jalPicDirectory = new File(picDirectory, "Just a Line");

            // make our directory if it doesn't exist
            if (!jalPicDirectory.exists()) {
                jalPicDirectory.mkdirs();
            }

            File newFile = new File(jalPicDirectory, file.getName());
            boolean success = copyFile(file, newFile);

            if (success) {
                Toast.makeText(getContext().getApplicationContext(),
                        getContext().getString(R.string.saved, directoryName), Toast.LENGTH_SHORT)
                        .show();
            } else {
                Toast.makeText(getContext().getApplicationContext(), R.string.could_not_save,
                        Toast.LENGTH_SHORT).show();
            }
        } else {
            // Request permissions
            if (mListener != null) {
                mListener.requestStoragePermission();
            }
        }
    }
 
Example 7
Source File: CaptureManager.java    From ViewCapture with Apache License 2.0 5 votes vote down vote up
private String getDirectoryName() {
    if (directoryName == null || directoryName.isEmpty()) {
        return Environment.DIRECTORY_PICTURES;
    } else {
        return directoryName;
    }
}
 
Example 8
Source File: MainActivity.java    From OneText_For_Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void shotOneTextViaMediaStore() {
    try {
        final String pic_file_path;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            pic_file_path = Environment.DIRECTORY_PICTURES + File.separator + "OneText" + File.separator;
        } else {
            pic_file_path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "OneText" + File.separator;
        }
        final String pic_file_name = "OneText " + System.currentTimeMillis() + ".jpg";
        Bitmap bitmap = SaveBitmapUtil.getCacheBitmapFromView(pic_layout);
        ContentResolver resolver = getContentResolver();
        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DISPLAY_NAME, pic_file_name);
        values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis());
        values.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            values.put(MediaStore.MediaColumns.RELATIVE_PATH, pic_file_path);
        } else {
            File path = new File(pic_file_path);
            //noinspection ResultOfMethodCallIgnored
            path.mkdirs();
            values.put(MediaStore.MediaColumns.DATA, path + File.separator + pic_file_name);
        }
        final Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        if (imageUri != null) {
            OutputStream stream = resolver.openOutputStream(imageUri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            if (stream != null) {
                stream.close();
            }
        }
        Snackbar.make(rootview, getString(R.string.save_succeed) + " " + pic_file_name, Snackbar.LENGTH_SHORT).setAction(R.string.share_text, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.putExtra(Intent.EXTRA_STREAM, imageUri);
                intent.setType("image/*");
                startActivity(Intent.createChooser(intent, getString(R.string.share_text)));
            }
        }).show();
    } catch (Exception e) {
        Snackbar.make(rootview, getString(R.string.save_fail), Snackbar.LENGTH_SHORT).show();
    }
}
 
Example 9
Source File: StorageUtil.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static File getImageDir() throws NoExternalStorageException {
  return new File(getSignalStorageDir(), Environment.DIRECTORY_PICTURES);
}
 
Example 10
Source File: StorageUtil.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public static File getImageDir() throws NoExternalStorageException {
    return new File(getExternalStorageDir(), Environment.DIRECTORY_PICTURES);
}
 
Example 11
Source File: MimiUtil.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
private static File getPicturesDirectoryAsFile() {
    return new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
}
 
Example 12
Source File: StorageUtil.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
public static File getImageDir() throws NoExternalStorageException {
  return new File(getStorageDir(), Environment.DIRECTORY_PICTURES);
}
 
Example 13
Source File: CuxtomCamActivity.java    From CuXtomCam with Apache License 2.0 4 votes vote down vote up
/**
 * Load all the extra values that have been sent by the calling activity
 * 
 * @param intent
 *            containing extras
 */
private void loadExtras(Intent intent) {
	// Check for CameraMode
	if (intent.hasExtra(CuxtomIntent.CAMERA_MODE)) {
		cameraMode = intent.getIntExtra(CuxtomIntent.CAMERA_MODE,
				CAMERA_MODE.PHOTO_MODE);
	} else {
		cameraMode = CAMERA_MODE.PHOTO_MODE;
	}

	// check for folder path where pictures will be saved
	if (intent.hasExtra(CuxtomIntent.FOLDER_PATH)) {
		folderPath = intent.getStringExtra(CuxtomIntent.FOLDER_PATH);
	} else {
		folderPath = Environment.getExternalStorageDirectory()
				+ File.separator + Environment.DIRECTORY_PICTURES
				+ File.separator + DEFAULT_DIRECTORY;
		createSubDirectory();
	}

	// Check for FileName
	if (intent.hasExtra(CuxtomIntent.FILE_NAME)) {
		fileName = intent.getStringExtra(CuxtomIntent.FILE_NAME);
	} else {
		String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
				.format(new Date());
		if (cameraMode == CAMERA_MODE.PHOTO_MODE) {
			fileName = "pic_" + timeStamp;
		} else {
			fileName = "vid_" + timeStamp;
		}
	}

	// Check for video duration
	if (cameraMode == CAMERA_MODE.VIDEO_MODE
			&& intent.hasExtra(CuxtomIntent.VIDEO_DURATION)) {
		video_duration = intent.getIntExtra(CuxtomIntent.VIDEO_DURATION,
				3600);
	} else {
		video_duration = 3600;
	}

	// check whether zoom functionailty should be enabled
	if (intent.hasExtra(CuxtomIntent.ENABLE_ZOOM)) {
		enablezoom = intent.getBooleanExtra(CuxtomIntent.ENABLE_ZOOM, true);
	} else {
		enablezoom = true;
	}

}