It is a little bit confusing to find out a way to create bottomsheet once I click a document from my android app and open. bottomsheet should be like this attached image and there should be a way to select existing document previewers in my device.
As per my knowledge iOS is having quick look future. My question is how do we implement same feature in android? Are there inbuild bottom sheet that can use directly in android app. Can't we use sharesheet option here?.
Asked
Active
Viewed 242 times
0

charitha amarasinghe
- 575
- 1
- 6
- 19
1 Answers
0
Below code will help you .
public void open_file(String filename) {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator + filename);
Uri uri = FileProvider.getUriForFile(getActivity(), getContext().getApplicationContext().getPackageName() + ".provider", file);
String mime = getContext().getContentResolver().getType(uri);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mime);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
public String get_mime_type(String url) {
String ext = MimeTypeMap.getFileExtensionFromUrl(url);
String mime = null;
if (ext != null) {
mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
}
return mime;
}
special note - to tackle with this code line
Uri uri = FileProvider.getUriForFile(getActivity(), getContext().getApplicationContext().getPackageName() + ".provider", file);
use this android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

charitha amarasinghe
- 575
- 1
- 6
- 19