Code example for Uri

Methods: getAuthority, getPath, toString

0
        ctx.revokeUriPermission(Uri.parse(rootUri), Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } 
     
    public static File fileFromUri(Uri uri) throws IllegalArgumentException
    { 
        String authority = uri.getAuthority();
        if(isCorrectAuthority(authority))
            return new File(PATH_PREFIX + authority + uri.getPath());
        else throw new IllegalArgumentException("Unknown URI authority: " + authority);
    } 
     
    @Override 
    public ParcelFileDescriptor openFile(Uri uri, String mode)
        throws FileNotFoundException, SecurityException 
    { 
        Logger.T(TAG, "Opening content: " + uri);
         
        if(mode.compareTo("r") != 0)
        { 
            throw new SecurityException("Unacceptable openFile mode: " + mode);
        } 
         
        try { 
            File path = fileFromUri(uri);
             
            Logger.D(TAG, "Opening content file: " + path.getPath());
             
            ParcelFileDescriptor fd = RhoFileApi.openParcelFd(path.getPath());
            if(fd == null)
                throw new IllegalArgumentException();
             
            return fd;
        } catch(IllegalArgumentException error)
        { 
            FileNotFoundException fileError = new FileNotFoundException("Cannot assign file for URI: " + uri.toString());
            fileError.initCause(error);
            throw fileError;
        } 
    }