Open files from Android application
<p>The application displays all the files(any file extensions) from SDCard to the user in a list view.</p>

<p>If the user clicks on the file , either of the following should occur:</p>

<p>i>If the file extension is  jpg / png ,  which is supported(Default) by Android , then the file should be opened directly i.e. without displaying the list of applications already installed on the device.</p>

<p>ii> If the file extension is unsupported by Android, then only the list of file viewer applications installed on the device should be displayed to the user.</p>

<p>Using the following code , but it is unable to take care of the above conditions.</p>

<pre><code>private void openFile(String filePath,String fileExtension) {
                Intent intent = new Intent();
                intent.setAction(android.content.Intent.ACTION_VIEW);
                File file = new File(filePath);
                MimeTypeMap mime = MimeTypeMap.getSingleton();
                String type = mime.getMimeTypeFromExtension(fileExtension);
                intent.setDataAndType(Uri.fromFile(file), type);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    startActivity(intent);
                } catch (android.content.ActivityNotFoundException e) {
                }
    }
</code></pre>

<p>Any hints/suggestions welcome.</p>
