forked from geode-sdk/android-launcher
pass file name to savefile intent
This commit is contained in:
2 files changed
+13
-9
No files matched your search
@@ -7,18 +7,25 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.DocumentsContract
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import java.io.File
|
||||
|
||||
open class GeodeSaveFileActivityResult : ActivityResultContract<GeodeSaveFileActivityResult.SaveFileParams, Uri?>() {
|
||||
class SaveFileParams(val mimeType: String?, val defaultPath: Uri?) {}
|
||||
class SaveFileParams(val mimeType: String?, val initialPath: File?)
|
||||
override fun createIntent(context: Context, input: SaveFileParams): Intent {
|
||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
.setType(input.mimeType ?: "*/*")
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (input.defaultPath != null) {
|
||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, input.defaultPath)
|
||||
|
||||
if (input.initialPath != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val uri = DocumentFile.fromFile(input.initialPath).uri
|
||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri)
|
||||
}
|
||||
|
||||
intent.putExtra(Intent.EXTRA_TITLE, input.initialPath.name)
|
||||
}
|
||||
|
||||
return intent
|
||||
}
|
||||
|
||||
|
||||
@@ -320,15 +320,12 @@ object GeodeUtils {
|
||||
|
||||
@JvmStatic
|
||||
fun createFile(path: String): Boolean {
|
||||
var uri: Uri?
|
||||
DocumentFile.fromFile(File(path)).also {
|
||||
uri = it.uri
|
||||
}
|
||||
val initialPath = File(path)
|
||||
|
||||
return try {
|
||||
checkForFilePermissions(
|
||||
onSuccess = {
|
||||
saveFileResultLauncher.launch(GeodeSaveFileActivityResult.SaveFileParams(null, uri))
|
||||
saveFileResultLauncher.launch(GeodeSaveFileActivityResult.SaveFileParams(null, initialPath))
|
||||
},
|
||||
onFailure = { failedCallback() }
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user