gpt4 book ai didi

java - 在相册或图库中创建一个文件夹,如 WhatsApp 图像、WhatsApp 视频

转载 作者:行者123 更新时间:2023-12-03 20:48:28 25 4
gpt4 key购买 nike

我的要求是在 Gallery/Albums 下显示目录,
以以下方式创建目录并不能完全满足我的要求...

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

final File localFile = new File(rootPath,fileName);
通过使用此代码,我可以通过使用带有路径的“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");
但没有运气,请帮助我的 friend
提前致谢。

最佳答案

也检查这个解决方案:

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);
}
}
});

关于java - 在相册或图库中创建一个文件夹,如 WhatsApp 图像、WhatsApp 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64318573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com