以编程方式创建文件夹后如何更新文件系统?

How can I update the File System after creating a folder programmatically?

我已经在 android 中以语法方式创建了一个文件夹,但是当通过 USB 数据线连接设备时它没有显示在文件资源管理器中。

下面是我用来扫描文件系统的一段源代码,但它不起作用。它给出错误权限拒绝(安全异常)

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
                            + Environment.getExternalStorageDirectory())));
                    MediaScannerConnection.scanFile(context, new String[]{new File(Environment.getExternalStorageDirectory().toString()).getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                        @Override
                        public void onScanCompleted(String path, Uri uri) {

                        }
                    });
                }

我正在使用具有 Android 7.0 (OS) 的 Android 设备。你能帮我解决这个问题吗?

尝试:

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
                    + Environment.getExternalStorageDirectory())));

        } else {
            MediaScannerConnection.scanFile(context, new String[]{new File(Environment.getExternalStorageDirectory().toString()).getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                @Override
                public void onScanCompleted(String path, Uri uri) {
                  //No need to call anything here
                }
            });
        }