Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取全部视频&;外部SD卡的图像大小_Android - Fatal编程技术网

Android 如何获取全部视频&;外部SD卡的图像大小

Android 如何获取全部视频&;外部SD卡的图像大小,android,Android,我正在尝试从外部SD卡计算总内存大小(视频和图像)。例如,有一个方法MediaStore.Audio.Media.getContentUriForPath(字符串路径)。从那里我可以得到URI并计算音频文件的大小。顺便 private long getMedia(Uri uri) { Log.e("URI",uri+""); String[] proj = { MediaStore.MediaColumns.SIZE }; Cursor cursor = ((Activi

我正在尝试从外部SD卡计算总内存大小(视频和图像)。例如,有一个方法
MediaStore.Audio.Media.getContentUriForPath(字符串路径)
。从那里我可以得到URI并计算音频文件的大小。顺便

private long getMedia(Uri uri) {
    Log.e("URI",uri+"");
    String[] proj = { MediaStore.MediaColumns.SIZE };
    Cursor cursor = ((Activity) context).getContentResolver().query(uri, proj, null, null, null);
    long size = DirectoryMediaSize.getMediaSize(cursor);
    cursor.close();
    return size;
}
没有像
MediaStore.Video.Media.getContentUriForPath()这样的方法。那么如何计算(视频和图像)的大小呢???

请尝试以下代码:-

                    Uri selectedImageURI = data.getData();
                    File imageFile = new File(getRealPathFromURI(selectedImageURI));

long check = ((imageFile.length() / 1024));
                    if (check < 5000)
                    {
                         // less then 5 mb
                    }
                    else 
                    {
                            // greater then 5 mb
                    }

如何获取sd卡的contentURI?getRealPathFromURI(selectedImageURI)使用此选项!很抱歉,我需要特定于视频或图像的总媒体大小。我有sd卡路径。有没有api或简单的方法来计算它,因为我发现它是MediaStore.Audio.Media.getContentUriForPath(字符串路径)??首先获取所有文件,然后获取大小!
String getRealPathFromURI(Uri contentURI)
    {
        String result;
        Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
        if (cursor == null)
        { // Source is Dropbox or other similar local file path
            result = contentURI.getPath();
        }
        else
        {
            cursor.moveToFirst();
            int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
            result = cursor.getString(idx);
            cursor.close();
        }
        return result;
    }