在相册或图库中创建 WhatsApp 图片、WhatsApp 视频等文件夹

Mob*_*ram 5 java directory android image gallery

我的要求是在图库/相册下显示目录,通过以下方式创建目录并不能完全满足我的要求...

 File rootPath = new File(Environment.getExternalStorageDirectory(), "directoryName"); 
 if(!rootPath.exists()) {
                rootPath.mkdirs();
            }

            final File localFile = new File(rootPath,fileName);
Run Code Online (Sandbox Code Playgroud)

通过使用此代码,我可以通过使用“file mangaer”和路径...“deviceStorage/directoryName”来查看该文件夹,但该文件夹在图库或相册下不可见

对于目录创建我也尝试了以下方法......

 1)File directory = new File(this.getFilesDir()+File.separator+"directoryName");

 2)File directory = new File (Environment.getExternalFilesDir(null) + "/directoryName/");

3)File directory = new File(Environment.
  getExternalStoragePublicDirectory(   
 (Environment.DIRECTORY_PICTURES).toString() + "/directoryName");
Run Code Online (Sandbox Code Playgroud)

但没有运气,请帮助我的朋友提前致谢。

小智 0

也检查这个解决方案:

String path = Environment.getExternalStorageDirectory().toString();
File dir = new File(path, "/appname/media/app images/");
if (!dir.isDirectory()) {
        dir.mkdirs();
}

File file = new File(dir, filename + ".jpg");
String imagePath =  file.getAbsolutePath();
    //scan the image so show up in album
MediaScannerConnection.scanFile(this,
        new String[] { imagePath }, null,
        new MediaScannerConnection.OnScanCompletedListener() {
        public void onScanCompleted(String path, Uri uri) {
        if(Config.LOG_DEBUG_ENABLED) {
            Log.d(Config.LOGTAG, "scanned : " + path);
        }
        }
});
Run Code Online (Sandbox Code Playgroud)