Skip to content Skip to sidebar Skip to footer

Get File Path From Uri From Video Chooser

In my app I start an Intent to pick a video file like this Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType('video/*'); startActivityForResult(intent, kVideoPi

Solution 1:

Your Uri does not necessarily represent a file on the disk. It begins with content:// meaning it is served up by the content provider for that type of file.

You don't actually need to use a file in the filesystem here (although, you can). What you want to do is stream the data from the content provider directly to the server.

There are some good examples - I would try this one for how to do this, in the first section "How to access binary data of existing content providers"

Solution 2:

  • Hello i know it is too late but recently i found the solution of same problem

    I was also facing the same problem but here is the method

    public static String getPath (final Context context, final Uri uri) {

    if (DEBUG)
            Log.d(TAG + " File -",
                    "Authority: " + uri.getAuthority() +
                            ", Fragment: " + uri.getFragment() +
                            ", Port: " + uri.getPort() +
                            ", Query: " + uri.getQuery() +
                            ", Scheme: " + uri.getScheme() +
                            ", Host: " + uri.getHost() +
                            ", Segments: " + uri.getPathSegments().toString()
                    );
    
        finalboolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    
        // DocumentProviderif (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
    
            // ExternalStorageProviderelseif (isExternalStorageDocument(uri)) {
                finalString docId = DocumentsContract.getDocumentId(uri);
                finalString[] split = docId.split(":");
                finalString type = split[0];
    
                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }
    
                // TODO handle non-primary volumes
            }
    
            // MediaProviderelseif (isMediaDocument(uri)) {
                finalString docId = DocumentsContract.getDocumentId(uri);
                finalString[] split = docId.split(":");
                finalString type = split[0];
    
                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } elseif ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } elseif ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
    
                finalString selection = "_id=?";
                finalString[] selectionArgs = newString[] {
                        split[1]
                };
    
                return getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
    
    // MediaStore (and general)elseif ("content".equalsIgnoreCase(uri.getScheme())) {
    
        // Return the remote addressif (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();
    
        return getDataColumn(context, uri, null, null);
    }
    // Fileelseif ("file".equalsIgnoreCase(uri.getScheme())) {
    
    
    return uri.getPath();
        }
    
        returnnull;
    }
    

which i get from this url

--> other methods can be fetched from this FILE UTILS file enjoy coding:) --> and it gets me full video path from the uri hope it helps you :)

Post a Comment for "Get File Path From Uri From Video Chooser"