|
|
|
@ -31,7 +31,7 @@ object FilePicker { |
|
|
|
|
0 -> default?.invoke() |
|
|
|
|
1 -> { |
|
|
|
|
try { |
|
|
|
|
val intent = getSelectDirIntent() |
|
|
|
|
val intent = createSelectDirIntent() |
|
|
|
|
activity.startActivityForResult(intent, requestCode) |
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
|
e.printStackTrace() |
|
|
|
@ -68,7 +68,7 @@ object FilePicker { |
|
|
|
|
0 -> default?.invoke() |
|
|
|
|
1 -> { |
|
|
|
|
try { |
|
|
|
|
val intent = getSelectDirIntent() |
|
|
|
|
val intent = createSelectDirIntent() |
|
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
|
e.printStackTrace() |
|
|
|
@ -106,7 +106,7 @@ object FilePicker { |
|
|
|
|
0 -> default?.invoke() |
|
|
|
|
1 -> { |
|
|
|
|
try { |
|
|
|
|
val intent = getSelectFileIntent() |
|
|
|
|
val intent = createSelectFileIntent() |
|
|
|
|
intent.type = type//设置类型 |
|
|
|
|
activity.startActivityForResult(intent, requestCode) |
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
@ -147,7 +147,7 @@ object FilePicker { |
|
|
|
|
0 -> default?.invoke() |
|
|
|
|
1 -> { |
|
|
|
|
try { |
|
|
|
|
val intent = getSelectFileIntent() |
|
|
|
|
val intent = createSelectFileIntent() |
|
|
|
|
intent.type = type//设置类型 |
|
|
|
|
fragment.startActivityForResult(intent, requestCode) |
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
@ -168,14 +168,14 @@ object FilePicker { |
|
|
|
|
}.show() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getSelectFileIntent(): Intent { |
|
|
|
|
private fun createSelectFileIntent(): Intent { |
|
|
|
|
val intent = Intent(Intent.ACTION_GET_CONTENT) |
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE) |
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) |
|
|
|
|
return intent |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getSelectDirIntent(): Intent { |
|
|
|
|
private fun createSelectDirIntent(): Intent { |
|
|
|
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) |
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) |
|
|
|
|
return intent |
|
|
|
|