I\'m working on an Android application which should be able to open a selected file from a specific folder.
I already tried this, but after selecting which applicati
Try the following code.
File file = new File(path); // path = your file path
lastSlash = file.toString().lastIndexOf('/');
if (lastSlash >= 0)
{
fileName = url.toString().substring(lastSlash + 1);
}
if (fileName.endsWith("pdf"))
{
mimeType = "application/pdf";
}
else
{
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension
(MimeTypeMap.getFileExtensionFromUrl(path));
}
Uri uri_path = Uri.fromFile(file);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.putExtra(PATH, path);
intent.putExtra(MIMETYPE, mimeType);
intent.setType(mimeType);
intent.setDataAndType(uri_path, mimeType);
startActivity(intent);