-
-
Notifications
You must be signed in to change notification settings - Fork 464
Expand file tree
/
Copy pathIntentFactory.kt
More file actions
36 lines (32 loc) · 1.05 KB
/
IntentFactory.kt
File metadata and controls
36 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.reactnativedocumentpicker
import android.content.Intent
import android.os.Build
import android.provider.DocumentsContract
object IntentFactory {
fun getPickIntent(options: PickOptions): Intent {
// TODO option for extra task on stack?
// reminder - flags are for granting rights to others
return Intent(options.action).apply {
val types = options.mimeTypes
type =
if (types.size > 1) {
putExtra(Intent.EXTRA_MIME_TYPES, types)
options.intentFilterTypes
} else {
types[0]
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
options.initialDirectoryUrl != null
) {
// only works for ACTION_OPEN_DOCUMENT
// TODO must be URI
putExtra(DocumentsContract.EXTRA_INITIAL_URI, options.initialDirectoryUrl)
}
if (!options.allowVirtualFiles) {
addCategory(Intent.CATEGORY_OPENABLE)
}
putExtra(Intent.EXTRA_LOCAL_ONLY, options.localOnly)
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, options.multiple)
}
}
}