Skip to content

Commit 8e579b1

Browse files
feat: improve launchApp
1 parent 69c0803 commit 8e579b1

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ private void openInBrowser(String src, CallbackContext callback) {
15641564
private void launchApp(
15651565
String appId,
15661566
String className,
1567-
String data,
1567+
JSONObject extras,
15681568
CallbackContext callback
15691569
) {
15701570
if (appId == null || appId.equals("")) {
@@ -1582,21 +1582,38 @@ private void launchApp(
15821582
intent.addCategory(Intent.CATEGORY_LAUNCHER);
15831583
intent.setPackage(appId);
15841584
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1585+
intent.setClassName(appId, className);
1586+
1587+
if (extras != null) {
1588+
Iterator<String> keys = extras.keys();
1589+
1590+
while (keys.hasNext()) {
1591+
String key = keys.next();
1592+
Object value = extras.get(key);
15851593

1586-
if (data != null && !data.equals("")) {
1587-
intent.putExtra("acode_data", data);
1594+
if (value instanceof Integer) {
1595+
intent.putExtra(key, (Integer) value);
1596+
} else if (value instanceof Boolean) {
1597+
intent.putExtra(key, (Boolean) value);
1598+
} else if (value instanceof Double) {
1599+
intent.putExtra(key, (Double) value);
1600+
} else if (value instanceof Long) {
1601+
intent.putExtra(key, (Long) value);
1602+
} else if (value instanceof String) {
1603+
intent.putExtra(key, (String) value);
1604+
} else {
1605+
intent.putExtra(key, value.toString());
1606+
}
1607+
}
15881608
}
15891609

1590-
intent.setClassName(appId, className);
15911610
activity.startActivity(intent);
15921611
callback.success("Launched " + appId);
1612+
15931613
} catch (Exception e) {
15941614
callback.error(e.toString());
1595-
return;
15961615
}
15971616

1598-
1599-
16001617
}
16011618

16021619

src/plugins/system/www/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ module.exports = {
126126
openInBrowser: function (src) {
127127
cordova.exec(null, null, 'System', 'open-in-browser', [src]);
128128
},
129-
launchApp: function (app, className, data, onSuccess, onFail) {
130-
cordova.exec(onSuccess, onFail, 'System', 'launch-app', [app, className, data]);
129+
launchApp: function (app, className, extras, onSuccess, onFail) {
130+
cordova.exec(onSuccess, onFail, 'System', 'launch-app', [app, className, extras]);
131131
},
132132
inAppBrowser: function (url, title, showButtons, disableCache) {
133133
var myInAppBrowser = {

0 commit comments

Comments
 (0)