@@ -15,41 +15,8 @@ fun Activity.sharePaths(paths: ArrayList<String>) {
1515 sharePathsIntent(paths, BuildConfig .APPLICATION_ID )
1616}
1717
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 )) {
18+ fun Activity.tryOpenPathIntent (path : String , forceChooser : Boolean , openAsText : Boolean = false) {
19+ if (! forceChooser && path.endsWith(" .apk" , true )) {
5320 val uri = if (isNougatPlus()) {
5421 FileProvider .getUriForFile(this , " ${BuildConfig .APPLICATION_ID } .provider" , File (path))
5522 } else {
@@ -67,12 +34,13 @@ fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, asText: Bool
6734 }
6835 }
6936 } else {
70- openPath(path, forceChooser)
37+ openPath(path, forceChooser, openAsText )
7138 }
7239}
7340
74- fun Activity.openPath (path : String , forceChooser : Boolean ) {
75- openPathIntent(path, forceChooser, BuildConfig .APPLICATION_ID )
41+ fun Activity.openPath (path : String , forceChooser : Boolean , openAsText : Boolean = false) {
42+ val mimeType = if (openAsText) " text/plain" else " "
43+ openPathIntent(path, forceChooser, BuildConfig .APPLICATION_ID , mimeType)
7644}
7745
7846fun Activity.setAs (path : String ) {
0 commit comments