Android: List of files of saved to the internal storage


Example get all files call recorder 3gpp

        File f = getContext().getFilesDir();
        String z = f.getPath();
 
        File[] paths;

        try {

            // create new filename filter
            FilenameFilter fileNameFilter = (dir, name) -> {
                if(name.lastIndexOf('.')>0) {

                    // get last index for '.' char
                    int lastIndex = name.lastIndexOf('.');

                    // get extension
                    String str = name.substring(lastIndex);

                    // match path name extension
                    if(str.equals(".3gpp")) {
                        return true;
                    }
                }

                return false;
            };

            // returns pathnames for files and directory
            paths = f.listFiles(fileNameFilter);

            // for each pathname in pathname array
            for(File path:paths) {

                // prints file and directory paths
                Timber.i("File:" + path.getPath()+" . Filesize:" + path.length());
            }

        } catch(Exception e) {
            // if any error occurs
            e.printStackTrace();
        }

Result:

2020-12-09 19:03:22.869 19268-19268/com.tutorialspots.www.callmanager I/LoginFragment: File:/data/user/0/com.tutorialspots.www.callmanager/files/record_08-12-2020 03-10-46.3gpp . Filesize:69937
2020-12-09 19:03:22.870 19268-19268/com.tutorialspots.www.callmanager I/LoginFragment: File:/data/user/0/com.tutorialspots.www.callmanager/files/record_08-12-2020 03-17-05.3gpp . Filesize:68785
2020-12-09 19:03:22.870 19268-19268/com.tutorialspots.www.callmanager I/LoginFragment: File:/data/user/0/com.tutorialspots.www.callmanager/files/record_08-12-2020 04-13-18.3gpp . Filesize:52333
2020-12-09 19:03:22.871 19268-19268/com.tutorialspots.www.callmanager I/LoginFragment: File:/data/user/0/com.tutorialspots.www.callmanager/files/(650) 555-1212_1607420520870.3gpp . Filesize:16919

Leave a Reply