In my android application I am using the below code to list out the mp3 files for select and upload.
I want to know is it possible to filter the files with their duration along with their type.
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
try {
startActivityForResult(Intent.createChooser(intent, "Select your Audio"), Global.FILE_FROM_SD);
}
catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(WizardStep1.this,
"Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
I don't think so, or at least not the way how you started.
I believe once you created the intent chooser and opened another file manager, then you cannot control what data to display you that particular file manager, like filtered by a particular criteria.
The solution I see here, is to create a method that returns all audio files from sdcard into an array, then use a filter to determine the extension of your files (.mp3) in conjuction with a method that gets the duration of a file.
Add the the filtered content to a new array, and then do what you want with your filtered files, for example display in a ListView
and let the user select the ones which he want to upload.
A pseudocode will look like this:
ArrayList<String> filteredFiles = new ArrayList<String>();
String[] audioFiles = getAllAudioFiles();
for (String file : audioFiles) {
if (file.endsWith(".mp3") && getDuration(file) >= DURATION_CONSTANT) {
filteredFiles.add(file);
}
}
Then display the content of filteredFiles
in a ListView
and provide the appropriate logic for selecting/uploading the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With