Java Code Examples for com.blankj.utilcode.util.FileUtils#getFileByPath()

The following examples show how to use com.blankj.utilcode.util.FileUtils#getFileByPath() . 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: CameraHandler.java    From FastWaiMai with MIT License 6 votes vote down vote up
private void takePhoto() {
	final String currentPhotoName = getPhotoName();
	final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	final File tempFile = new File(FileUtil.CAMERA_PHOTO_DIR, currentPhotoName);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
		final ContentValues contentValues = new ContentValues(1);
		contentValues.put(MediaStore.Images.Media.DATA, tempFile.getPath());
		final Uri uri = DELEGATE.getContext().getContentResolver().
				insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
		//需要将Uri路径转化为实际路径
		final File realFile =
				FileUtils.getFileByPath(FileUtil.getRealFilePath(DELEGATE.getContext(), uri));
		final Uri realUri = Uri.fromFile(realFile);
		CameraImageBean.getInstance().setPath(realUri);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
	} else {
		final Uri fileUri = Uri.fromFile(tempFile);
		CameraImageBean.getInstance().setPath(fileUri);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
	}
	DELEGATE.startActivityForResult(intent, CameraRequestCodes.TAKE_PHOTO);

}
 
Example 2
Source File: MD5Util.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
public static String getVideoFileHash(String filePath) {
    try {
        File file = FileUtils.getFileByPath(filePath);
        if (file != null) {
            if (file.length() < 16 * 1024 * 1024) {
                return getFileMD5String(file);
            } else {
                RandomAccessFile r = new RandomAccessFile(file, "r");
                r.seek(0);
                byte[] bs = new byte[16 * 1024 * 1024];
                r.read(bs);
                return getMD5String(bs);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}