Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it Possible to filter with duration of .mp3 file While Using Intent.createchooser?

Tags:

android

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();
}
like image 314
Renjith K N Avatar asked Jan 03 '13 09:01

Renjith K N


1 Answers

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.

like image 139
Andy Res Avatar answered Nov 15 '22 00:11

Andy Res