Java Code Examples for android.os.Environment#DIRECTORY_DCIM

The following examples show how to use android.os.Environment#DIRECTORY_DCIM . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
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 Project: Simpler   File: FileUtils.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * 创建根缓存目录
 *
 * @return
 */
public static String getRootPath(Context context) {
    String rootPath = "";
    if (isSdCardAvailable()) {
        // 图片保存到相册
        rootPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                + File.separator + Environment.DIRECTORY_DCIM + File.separator + "Camera";
        File file = new File(rootPath);
        if (!file.exists()) {
            file.mkdirs();
        }
    } else {
        // /data/data/<application package>/cache
        rootPath = context.getCacheDir().getPath();
    }
    return rootPath;
}
 
Example 4
Source Project: filemanager   File: FileUtils.java    License: 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 5
Source Project: Simpler   File: CommonUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 拍照
     */
    public static String capture(Activity activity, int requestCode) {
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        String picName = null;
        if (cameraIntent.resolveActivity(activity.getPackageManager()) != null) {
            if (BaseConfig.sSDCardExist) {
                picName = Environment.getExternalStorageDirectory().getAbsolutePath() +
                        File.separator + Environment.DIRECTORY_DCIM + File.separator +
                        "Camera" + File.separator + activity.getString(R.string.app_name) +
                        "_" + System.currentTimeMillis() + ".jpg";

            } else {
                picName = activity.getCacheDir().getPath() + File.separator +
                        activity.getString(R.string.app_name) + "_" + System.currentTimeMillis() + ".jpg";
            }
            File photoFile = new File(picName);
//            FileUtils.createFile(photoFile);

            Uri uri = FileProvider.getUriForFile(activity,
                    App.getInstance().getApplicationId() + ".provider", photoFile);

            List<ResolveInfo> resInfoList = activity.getPackageManager()
                    .queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                        | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            activity.startActivityForResult(cameraIntent, requestCode);
        } else {
            AppToast.showToast(R.string.open_camera_failure);
        }
        return picName;
    }
 
Example 6
Source Project: SoBitmap   File: LocalFileTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected List<String> doInBackground(Void... params) {
    File dir = new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/Camera");
    if (dir.exists()) {
        List<String> data = new ArrayList<>();
        for (File f : dir.listFiles()) {
            if (f.isFile()) {
                data.add(f.getAbsolutePath());
            }
        }
        return data;
    }
    return null;
}
 
Example 7
Source Project: bither-android   File: ImageFileUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static File getImageForGallery(long timeMillis) {
    String pictureName = getImageNameForGallery(timeMillis);
    File dcimFile = new File(Environment.getExternalStorageDirectory()
            + File.separator + Environment.DIRECTORY_DCIM, "Camera");
    if (!dcimFile.exists()) {
        dcimFile.mkdirs();
    }
    File file = new File(dcimFile, formatFileName(pictureName));
    return file;
}
 
Example 8
Source Project: Android-Next   File: ImageUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static File getMediaDir(String dirName) {
    File dcim = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM);
    File mediaDir = new File(dcim, dirName);
    if (!mediaDir.exists()) {
        mediaDir.mkdirs();
    }
    return mediaDir;
}
 
Example 9
Source Project: LyricHere   File: FileUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static File getDcimFolder() {
    return new File("/sdcard/" + Environment.DIRECTORY_DCIM);
}