Programing Center
Member
Hi
i want to get the list of running applications. i want to use this code https://stackoverflow.com/questions...ist-of-running-applications/22503513#22503513
and i write this code
and give me Errors
what should i do?
and Where should I change it to get the list of running applications? no log
it means i want to have dim list_running_aplication as list ?
i want to get the list of running applications. i want to use this code https://stackoverflow.com/questions...ist-of-running-applications/22503513#22503513
and i write this code
B4X:
Dim NativeMe As JavaObject
#if java
import anywheresoftware.b4a.BA;
import android.content.pm.PackageManager;
import java.util.List;
import android.content.pm.ApplicationInfo;
BA ba;
public String getActiveApps() {
PackageManager pm = ba.context.getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
String value = ""; // basic date stamp
value += "---------------------------------\n";
value += "Active Apps\n";
value += "=================================\n";
for (ApplicationInfo packageInfo : packages) {
//system apps! get out
if (!isSTOPPED(packageInfo) && !isSYSTEM(packageInfo)) {
value += getApplicationLabel(packageInfo.packageName) + "\n" + packageInfo.packageName + "\n-----------------------\n";
}
}
return value;
}
private boolean isSTOPPED(ApplicationInfo pkgInfo) {
return ((pkgInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0);
}
private boolean isSYSTEM(ApplicationInfo pkgInfo) {
return ((pkgInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
}
public String getApplicationLabel(String packageName) {
PackageManager packageManager = ba.context.getPackageManager();
List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
String label = null;
for (int i = 0; i < packages.size(); i++) {
ApplicationInfo temp = packages.get(i);
if (temp.packageName.equals(packageName))
label = packageManager.getApplicationLabel(temp).toString();
}
return label;
}
#End If
NativeMe.InitializeContext
dim list_running_aplication as list = NativeMe.RunMethod("getActiveApps",Array As String(""))
and give me Errors
B4X:
** Activity (main) Create, isFirst = true **
Error occurred on line: 79 (Main)
java.lang.RuntimeException: Method: getActiveApps not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.examplee.main.afterFirstLayout(main.java:109)
at b4a.examplee.main.access$000(main.java:21)
at b4a.examplee.main$WaitForLayout.run(main.java:87)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5601)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
** Activity (main) Resume **
what should i do?
and Where should I change it to get the list of running applications? no log
it means i want to have dim list_running_aplication as list ?