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