我正在写一张动态墙纸,需要一些帮助。我的墙纸将在用户在“设置...”中选择的另一个图像或现有墙纸(而不是另一个活动墙纸)上创建效果。
我的问题是:我找不到一种方法来列出手机上的静态壁纸或图像。我见过一些获取相机图像的例子,但没有看到壁纸。
任何帮助都将不胜感激。
发布于 2010-09-05 06:16:17
如果这有帮助,这里有一个我写的FileFilter,它将返回包含图像的文件夹列表。您只需使用.listFiles(filterForImageFolders)获取一个表示目录的文件(我将其用于Environment.getExternalStorageDirectory()),它将返回包含图像的目录的File[]。然后,您可以使用此列表在您的设置中填充图像列表:
FileFilter filterForImageFolders = new FileFilter()
{
public boolean accept(File folder)
{
try
{
//Checking only directories, since we are checking for files within
//a directory
if(folder.isDirectory())
{
File[] listOfFiles = folder.listFiles();
if (listOfFiles == null) return false;
//For each file in the directory...
for (File file : listOfFiles)
{
//Check if the extension is one of the supported filetypes
for (String ext : imageExtensions)
{
if (file.getName().endsWith("." + ext)) return true;
}
}
}
return false;
}
catch (SecurityException e)
{
Log.v("debug", "Access Denied");
return false;
}
}
};(ImageExtensions是包含"png","bmp","jpg",“jpeg”的String[] )
https://stackoverflow.com/questions/3644122
复制相似问题