Skip to content

Commit e58b7f5

Browse files
committed
Upload file
1 parent fc8afad commit e58b7f5

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public abstract class ShellHandlerBase extends Handler {
4242
* 处理Exitvalue
4343
*/
4444
public static final int EVENT_EXIT = -2;
45+
46+
protected abstract Context getContext();
4547

4648
protected abstract void onToast(String text);
4749

@@ -146,34 +148,30 @@ protected void onError(Object msg) {
146148

147149
protected void onAm(String type, String args) {
148150
try {
149-
// Lấy Application Context nội bộ (KHÔNG cần truyền)
150-
Context context = android.app.ActivityThread
151-
.currentApplication()
152-
.getApplicationContext();
153-
154-
if (context == null) return;
151+
Context ctx = getContext();
152+
if (ctx == null) return;
155153

156154
Intent intent = parseIntentArgs(args);
157155

158156
switch (type) {
159157
case "start":
160158
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
161-
context.startActivity(intent);
159+
ctx.startActivity(intent);
162160
break;
163161

164162
case "broadcast":
165-
context.sendBroadcast(intent);
163+
ctx.sendBroadcast(intent);
166164
break;
167165

168166
case "service":
169167
if (Build.VERSION.SDK_INT >= 26) {
170-
context.startForegroundService(intent);
168+
ctx.startForegroundService(intent);
171169
} else {
172-
context.startService(intent);
170+
ctx.startService(intent);
173171
}
174172
break;
175173
}
176-
} catch (Throwable e) {
174+
} catch (Exception e) {
177175
e.printStackTrace();
178176
}
179177
}

0 commit comments

Comments
 (0)