ArrayList<String> toBeScanned = new ArrayList<String>();
File folder_file = new File("sdcard/DCIM/Camera");
File[] files = folder_file.listFiles();
if (files != null) {
for (File file : files) {
// checking the File is file or directory
if (file.isFile()) {
String path = file.getAbsolutePath();
toBeScanned.add(path);
}
}
}
String[] toBeScannedStr = new String[toBeScanned.size()];
toBeScannedStr = toBeScanned.toArray(toBeScannedStr);
MediaScannerConnection.scanFile(MainActivity.this, toBeScannedStr, null, new MediaScannerConnection.OnScanCompletedListener()
{
@Override
public void onScanCompleted(String path, Uri uri) {
System.out.println("SCAN COMPLETED: " + path);
}
});
其中API的解释:?
?里面的关键类MediaScannerConnection 解释:
?
|