Q:

I want to download the file from server and view the file in android with various file Extensions like (pdf,doc,mp4,jpeg))

I want to download the file from server and view the file in android with various file Extensions like (pdf,doc,mp4,jpeg)
i have try this 
Intent intent = new Intent(Intent.ACTION_VIEW);
       File file1 = new File(Environment.getExternalStorageDirectory(),"report.pdf");

       intent.setDataAndType( Uri.fromFile( file1 ), "application/.*" );

     startActivity(intent);

but no success
should i have to give the individual extension in this 
please suggest the way to solve this  

A:

See this code for your reference
filePath is a actual path of the file 
                        Uri fileUri = Uri.fromFile(new File(filePath));

                        Uri new_uri = Uri.parse("file://"
                                + fileUri.getPath());

                        Intent intent = new Intent(Intent.ACTION_VIEW,
                                new_uri);

                        MimeTypeMap myMime = MimeTypeMap.getSingleton();
                        String fileExt = filePath.substring(filePath
                                .lastIndexOf(".") + 1);
                        String mimeType = myMime
                                .getMimeTypeFromExtension(fileExt);
                        intent.setDataAndType(new_uri, mimeType);

                        startActivity(intent);

