Skip to content

Commit 906f220

Browse files
fix. launchApp function (Acode-Foundation#1249)
* fix. launchApp function * update comment * Delete www/index.html --------- Co-authored-by: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com>
1 parent 28e4dc6 commit 906f220

File tree

4 files changed

+43
-210
lines changed

4 files changed

+43
-210
lines changed

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import android.content.ClipData;
66
import android.content.Context;
77
import android.content.Intent;
8-
import android.content.pm.ApplicationInfo;
9-
import android.content.pm.PackageInfo;
10-
import android.content.pm.PackageManager;
11-
import android.content.pm.ShortcutInfo;
12-
import android.content.pm.ShortcutManager;
138
import android.content.res.Configuration;
9+
import android.content.*;
10+
import android.content.pm.*;
11+
import java.util.*;
1412
import android.graphics.Bitmap;
1513
import android.graphics.Color;
1614
import android.graphics.ImageDecoder;
@@ -582,21 +580,42 @@ private void openInBrowser(String src, CallbackContext callback) {
582580

583581
private void launchApp(
584582
String appId,
585-
String action,
586-
String value,
583+
String className,
584+
String data,
587585
CallbackContext callback
588-
) {
589-
Intent intent = context
590-
.getPackageManager()
591-
.getLaunchIntentForPackage(appId);
592-
if (intent == null) {
593-
callback.error("App not found");
586+
) {
587+
if (appId == null || appId.equals("")) {
588+
callback.error("No package name provided.");
594589
return;
595590
}
596-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
597-
context.startActivity(intent);
598-
callback.success("Launched " + appId);
599-
}
591+
592+
if (className == null || className.equals("")) {
593+
callback.error("No activity class name provided.");
594+
return;
595+
}
596+
597+
try{
598+
Intent intent = new Intent(Intent.ACTION_MAIN);
599+
intent.addCategory(Intent.CATEGORY_LAUNCHER);
600+
intent.setPackage(appId);
601+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
602+
603+
if (data != null && !data.equals("")) {
604+
intent.putExtra("acode_data", data);
605+
}
606+
607+
intent.setClassName(appId, className);
608+
activity.startActivity(intent);
609+
callback.success("Launched " + appId);
610+
}catch(Exception e){
611+
callback.error(e.toString());
612+
return;
613+
}
614+
615+
616+
617+
}
618+
600619

601620
private void addShortcut(
602621
String id,

src/plugins/system/system.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,16 @@ interface System {
189189
openInBrowser(src: string): void;
190190
/**
191191
* Launches and app
192-
* @param app
193-
* @param action
194-
* @param value
192+
* @param app the package name of the app
193+
* @param className the full class name of the activity
194+
* @param data Data to pass to the app
195195
* @param onSuccess
196196
* @param onFail
197197
*/
198198
launchApp(
199199
app: string,
200-
action: string,
201-
value: string,
200+
className: string,
201+
data: string,
202202
onSuccess: OnSuccessBool,
203203
onFail: OnFail,
204204
): void;

src/plugins/system/www/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ module.exports = {
6565
openInBrowser: function (src) {
6666
cordova.exec(null, null, 'System', 'open-in-browser', [src]);
6767
},
68-
launchApp: function (app, action, value, onSuccess, onFail) {
69-
cordova.exec(onSuccess, onFail, 'System', 'launch-app', [app, action, value]);
68+
launchApp: function (app, className, data, onSuccess, onFail) {
69+
cordova.exec(onSuccess, onFail, 'System', 'launch-app', [app, className, data]);
7070
},
7171
inAppBrowser: function (url, title, showButtons, disableCache) {
7272
var myInAppBrowser = {

www/index.html

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)