android: 根据文件uri 获取文件名

public static String getFileRealNameFromUri(Context context, Uri fileUri) {
        if (context == null || fileUri == null) return null;
        DocumentFile documentFile = DocumentFile.fromSingleUri(context, fileUri);
        if (documentFile == null) return null;
        return documentFile.getName();
}

 

See:

1. ContentResolver - 如何从Uri获取文件名

2. StackOverFlow: Get filename and path from URI from mediastore

posted @ 2020-02-27 20:57  夜行过客  阅读(7191)  评论(2编辑  收藏  举报