Skip to content

Commit 0804899

Browse files
committed
Upload file
1 parent 7217d88 commit 0804899

2 files changed

Lines changed: 32 additions & 419 deletions

File tree

common/src/main/java/com/omarea/common/shell/ShellTranslation.kt

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ class ShellTranslation(val context: Context) {
6868
try {
6969
val intent = parseIntentArgs(subArgs)
7070

71+
if (intent.action == Intent.ACTION_SEND
72+
|| intent.action == Intent.ACTION_SEND_MULTIPLE
73+
) {
74+
val uri =
75+
intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
76+
?: intent.data
77+
if (uri != null) {
78+
intent.putExtra(Intent.EXTRA_STREAM, uri)
79+
intent.clipData = ClipData.newRawUri(null, uri)
80+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
81+
intent.data = null
82+
}
83+
}
84+
7185
when (cmd) {
7286
"start" -> {
7387
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -76,7 +90,10 @@ class ShellTranslation(val context: Context) {
7690
&& intent.component == null
7791
) {
7892
val chooser = Intent.createChooser(intent, null)
79-
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
93+
chooser.addFlags(
94+
Intent.FLAG_ACTIVITY_NEW_TASK or
95+
Intent.FLAG_GRANT_READ_URI_PERMISSION
96+
)
8097
ctx.startActivity(chooser)
8198
} else {
8299
ctx.startActivity(intent)
@@ -118,7 +135,13 @@ class ShellTranslation(val context: Context) {
118135
// data uri
119136
"-d" -> {
120137
if (i + 1 < tokens.size) {
121-
intent.data = Uri.parse(tokens[++i])
138+
var value = stripQuote(tokens[++i])
139+
val uri = when {
140+
value.contains("://") -> Uri.parse(value)
141+
value.startsWith("/") -> Uri.fromFile(File(value))
142+
else -> Uri.parse(value)
143+
}
144+
intent.data = uri
122145
}
123146
}
124147

@@ -217,8 +240,13 @@ class ShellTranslation(val context: Context) {
217240
"--eu" -> {
218241
if (i + 2 < tokens.size) {
219242
val key = tokens[++i]
220-
val value = tokens[++i]
221-
intent.putExtra(key, Uri.parse(value))
243+
var value = stripQuote(tokens[++i])
244+
val uri = when {
245+
value.contains("://") -> Uri.parse(value)
246+
value.startsWith("/") -> Uri.fromFile(File(value))
247+
else -> Uri.parse(value)
248+
}
249+
intent.putExtra(key, uri)
222250
}
223251
}
224252

0 commit comments

Comments
 (0)