編輯:關於Android編程
實現對文件夾的遞歸掃描
libmedia – libmedia.so
frameworksavmedialibmediaMediaScanner.cpp
由JNI調用processDirectory,然後由doProcessDirectory和doProcessDirectoryEntry實現對文件夾的遞歸掃描。
循環掃描該文件夾內的所有項
MediaScanResult MediaScanner::doProcessDirectory(
char *path, int pathRemaining, MediaScannerClient &client, bool noMedia) {
char* fileSpot = path + strlen(path);
struct dirent* entry;
.....
// Treat all files as non-media in directories that contain a .nomedia file
.....
//Skip .nomedia file
DIR* dir = opendir(path);
MediaScanResult result = MEDIA_SCAN_RESULT_OK;
while ((entry = readdir(dir))) {
if (doProcessDirectoryEntry(path, pathRemaining, client, noMedia, entry, fileSpot)
== MEDIA_SCAN_RESULT_ERROR) {
result = MEDIA_SCAN_RESULT_ERROR;
break;
}
}
closedir(dir);
return result;
}
判斷該項目是文件、文件夾還是需要跳過的項。
if 文件夾
doProcessDirectory
else if 文件
通過JNI調用java層scanFile
else if skip
skip this file or folder
MediaScanResult MediaScanner::doProcessDirectoryEntry(
char *path, int pathRemaining, MediaScannerClient &client, bool noMedia,
struct dirent* entry, char* fileSpot) {
struct stat statbuf;
const char* name = entry->d_name;
........
int type = entry->d_type;
if (type == DT_UNKNOWN) {
if (stat(path, &statbuf) == 0) {
if (S_ISREG(statbuf.st_mode)) {
//文件
type = DT_REG;
} else if (S_ISDIR(statbuf.st_mode)) {
//文件夾
type = DT_DIR;
}
}
}
if (type == DT_DIR) {
bool childNoMedia = noMedia;
// set noMedia flag on directories with a name that starts with '.'
// for example, the Mac .Trashes directory
if (name[0] == '.')
childNoMedia = true;
// report the directory to the client
if (stat(path, &statbuf) == 0) {
status_t status = client.scanFile(path, statbuf.st_mtime, 0,
true /*isDirectory*/, childNoMedia);
if (status) {
return MEDIA_SCAN_RESULT_ERROR;
}
}
// and now process its contents
strcat(fileSpot, /);
MediaScanResult result = doProcessDirectory(path, pathRemaining - nameLength - 1,
client, childNoMedia);
if (result == MEDIA_SCAN_RESULT_ERROR) {
return MEDIA_SCAN_RESULT_ERROR;
}
} else if (type == DT_REG) {
stat(path, &statbuf);
status_t status = client.scanFile(path, statbuf.st_mtime, statbuf.st_size,
false /*isDirectory*/, noMedia);
if (status) {
return MEDIA_SCAN_RESULT_ERROR;
}
}
return MEDIA_SCAN_RESULT_OK;
}
有朋友在問微信無法發送語音怎麼辦,微信無法語音解決方法有哪些呢?我們最常使用的微信功能就是與好友語音,所以遇到微信不能發送語音這樣故障的朋友一定很著急吧,希
viewpager 在滑動的過程中是如何觸發view身上的事件的,換句話說,viewpager在滑動的過程中到底是滑動的它裡面的view,還是滑動的viewpager本身
華為手機也可以刷刷消費啦!作為國內率先商用、支持NFC+指紋支付、以用戶體驗和支付安全為核心的Huawei Pay,擁有四重保障,芯片級安全;無需聯網,無需
首先需要做的是實現幾個頁面的跳轉,既類似微信的點擊按鈕,切換頁面。 話不多說,這是一個簡單的頁面切換的Demo,先貼幾張實現的效果: 圖片的底部是5個RadioButt