@@ -15,8 +15,41 @@ fun Activity.sharePaths(paths: ArrayList<String>) {
1515 sharePathsIntent(paths, BuildConfig .APPLICATION_ID )
1616}
1717
18- fun Activity.tryOpenPathIntent (path : String , forceChooser : Boolean ) {
19- if (! forceChooser && path.endsWith(" .apk" , true )) {
18+ fun Activity.tryOpenPathIntent (path : String , forceChooser : Boolean , asText : Boolean = false) {
19+ if (asText) {
20+
21+ // TODO: Improve
22+
23+ val uri = if (isNougatPlus()) {
24+ FileProvider .getUriForFile(this , " ${BuildConfig .APPLICATION_ID } .provider" , File (path))
25+ } else {
26+ Uri .fromFile(File (path))
27+ }
28+
29+ Intent ().apply {
30+ action = Intent .ACTION_VIEW
31+
32+ val mimeType = " text/plain"
33+ setDataAndType(uri, mimeType)
34+
35+ addFlags(Intent .FLAG_GRANT_READ_URI_PERMISSION )
36+
37+ if (resolveActivity(packageManager) != null ) {
38+ val chooser = Intent .createChooser(this , getString(R .string.open_with))
39+ try {
40+ startActivity(if (forceChooser) chooser else this )
41+ } catch (e: NullPointerException ) {
42+ showErrorToast(e)
43+ }
44+ } else {
45+ if (! tryGenericMimeType(this , mimeType, uri)) {
46+ toast(R .string.no_app_found)
47+ }
48+ }
49+
50+ }
51+ }
52+ else if (! forceChooser && path.endsWith(" .apk" , true )) {
2053 val uri = if (isNougatPlus()) {
2154 FileProvider .getUriForFile(this , " ${BuildConfig .APPLICATION_ID } .provider" , File (path))
2255 } else {
0 commit comments