Skip to content

Commit 3449e1c

Browse files
committed
Upload file
1 parent 1bd1acf commit 3449e1c

1 file changed

Lines changed: 41 additions & 22 deletions

File tree

krscript/src/main/java/com/omarea/krscript/model/ShellHandlerBase.java

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,46 @@ protected void onError(Object msg) {
152152
}
153153

154154
protected void onAm(String type, String args) {
155-
try {
156-
Context ctx = getContext();
157-
if (ctx == null) return;
155+
Context ctx = getContext();
156+
if (ctx == null) return;
158157

159-
Intent intent = parseIntentArgs(args);
158+
new Thread(() -> {
159+
try {
160+
Intent intent = parseIntentArgs(args);
160161

161-
switch (type) {
162-
case "start":
163-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
164-
ctx.startActivity(intent);
165-
break;
162+
switch (type) {
163+
case "start": {
164+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
166165

167-
case "broadcast":
168-
ctx.sendBroadcast(intent);
169-
break;
166+
if (Intent.ACTION_SEND.equals(intent.getAction())
167+
&& intent.getComponent() == null) {
170168

171-
case "service":
172-
if (Build.VERSION.SDK_INT >= 26) {
173-
ctx.startForegroundService(intent);
174-
} else {
175-
ctx.startService(intent);
169+
Intent chooser = Intent.createChooser(intent, null);
170+
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
171+
ctx.startActivity(chooser);
172+
173+
} else {
174+
ctx.startActivity(intent);
175+
}
176+
break;
176177
}
177-
break;
178+
179+
case "broadcast":
180+
ctx.sendBroadcast(intent);
181+
break;
182+
183+
case "service":
184+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
185+
ctx.startForegroundService(intent);
186+
} else {
187+
ctx.startService(intent);
188+
}
189+
break;
190+
}
191+
} catch (Exception e) {
192+
e.printStackTrace();
178193
}
179-
} catch (Exception e) {
180-
e.printStackTrace();
181-
}
194+
}, "am-dispatcher").start();
182195
}
183196

184197
private Intent parseIntentArgs(String args) {
@@ -197,7 +210,13 @@ private Intent parseIntentArgs(String args) {
197210
if (i + 1 >= tokens.length) break;
198211
intent.setData(Uri.parse(tokens[++i]));
199212
break;
200-
213+
214+
case "-t": { // mime type
215+
if (i + 1 >= tokens.length) break;
216+
intent.setType(tokens[++i]);
217+
break;
218+
}
219+
201220
case "-n": { // component
202221
if (i + 1 >= tokens.length) break;
203222
String[] cn = tokens[++i].split("/", 2);

0 commit comments

Comments
 (0)