File traversal and deletion in android ndk and androidndk
During Mobile Phone development, it is inevitable to perform some local file management operations. For example, many common apps, such as Weibo, have the cache clearing function. This function is used to traverse the app's own cache directory, delete All cached files. Java's File class can be used to implement local File traversal and deletion. How can I implement ndk? I have previously written "using win32 api to traverse folders Based on c ++". This method is unavailable because the android ndk platform belongs to the linux system. By searching for file management related information in linux, the file traversal and deletion functions are successfully implemented. The following Code contains the <dirent. h> header file.
// Delete All JNIEXPORT void JNICALL objects (JNIEnv * env, jclass obj, jstring fileFolder) {const char * file_folder = (* env)-> GetStringUTFChars (env, fileFolder, 0); DIR * pDir = NULL; struct dirent * dmsg; char szFileName [128]; char szFolderName [128]; strcpy (szFolderName, file_folder); strcat (szFolderName, "/% s"); if (pDir = opendir (file_folder ))! = NULL) {// traverse the directory and delete the file while (dmsg = readdir (pDir ))! = NULL) {if (strcmp (dmsg-> d_name ,".")! = 0 & strcmp (dmsg-> d_name ,"..")! = 0) {sprintf (szFileName, szFolderName, dmsg-> d_name); remove (szFileName) ;}} if (pDir! = NULL) {closedir (pDir);} (* env)-> ReleaseStringUTFChars (env, fileFolder, file_folder );}By the way, another implementation method is provided. This file Traversal method must include <io. h> the header file can be used for testing in windows. However, after being transplanted to the android ndk environment, the system prompts that the header file cannot be found during compilation, probably because of my ndk path configuration problems, later, I did not detail the specific reasons.
long hFile = 0;struct _finddata_t file_info;hFile = _findfirst("test\\*", &file_info);while (_findnext(hFile, & file_info) == 0){if (strcmp(file_info. name, ".") != 0 && strcmp(file_info. name, "..") != 0){printf("%s\n", file_info.name);}else{printf("%s\n", "invalid");}}_findclose(hFile);
Questions about the applicationmk file in android NDK Development
Application. mk is an mk file only available in android, and it also has the mk file feature.-D is a macro definition. You can remove this sentence and run it to know where to call it, and the application. mk file is used. a.
Android NDK writes database files in the specified path
In fact, you can call SqliteHelper of Android to create a new database, and copy your database structure to the new database.