Media scanning specific folder
Use below code to get the files from specific folder:
File folder_file = new File("give specific folder path");
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();
String extension = path
.substring(path.lastIndexOf(".") + 1);
// if the file is audio type, then save it to the database
if (extension.equalsIgnoreCase("mp4")) {
System.out.println(path + " is a media file ");
}
}
}
}
Try this for scanning files:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
.parse("file://"
+ Environment.getExternalStorageDirectory())));
Android How to use MediaScannerConnection scanFile
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
How to use MediaScannerConnection scanFile?
MediaScannerConnection.scanFile(this, new String[]{file.getPath()},
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
// now visible in gallery
}
});
Trigger mediascanner on specific path (folder), how to?
Hey I found out how to do it with a very simple code.
Just call this line of code:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
This should trigger mediascanner.
Related Topics
Edittext Seterror() with Icon But Without Popup Message
Pass Arraylist<? Implements Parcelable> to Activity
How to Run Media Scanner in Android
Cmusphinx Pocketsphinx - Recognize All (Or Large Amount) of Words
Problem to Achieve Curved Animation
I Can't Find the Android Keytool
Asynctask and Error Handling on Android
Android N Requires the Ide to Be Running with Java 1.8 or Later
Decoding Bitmaps in Android with the Right Size
Collapsingtoolbarlayout Subtitle
Android Edittext Onchange Listener
Creating a PDF File in Android Programmatically and Writing in It
Android Exception: Did You Forget to Call 'Public Void Setup (Localactivitymanager Activitygroup)'
How to Send JSON Object to Server Using Volley in Android
Android: Collapsingtoolbarlayout and Swiperefreshlayout Get Stuck