does any one know how i get this script to list all the installed apps to work inside LLX.
/*
List apps = getPackageManager().getInstalledPackages(0);
This method returns the list of PackageInfo (which contains overall information about the contents of a package). In other words, the method getInstalledPackages() will return a list containing all the information about all the installed application.
In this example, we will extract just the informations (packageName, appName, versionName, versionCode, and the icon), so we create a bean to store this informations:
*/
public class AppInfo {
private String name;
private String packageName;
private String versionName;
private int versionCode = 0;
private Drawable icon;
public AppInfo() {}
public Intent getLaunchIntent(Context context) {
Intent intentLaunch = context.getPackageManager().getLaunchIntentForPackage(this.packageName);
return intentLaunch;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public int getVersionCode() {
return versionCode;
}
public void setVersionCode(int versionCode) {
this.versionCode = versionCode;
}
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
}
/*
The last thing is to extract the application’s informations from the list of installed apps and store them in arraylist :
*/
/**
* get the list of all installed applications in the device
*@return ArrayList of installed applications or null
*/
private static ArrayList getListOfInstalledApp(Context context) {
PackageManager packageManager = context.getPackageManager();
List apps = packageManager.getInstalledPackages(PackageManager.SIGNATURE_MATCH);
if (apps != null && !apps.isEmpty()) {
ArrayList installedApps = new ArrayList();
for (int i = 0; i < apps.size(); i++) {
PackageInfo p = apps.get(i);
ApplicationInfo appInfo = null;
try {
appInfo = packageManager.getApplicationInfo(p.packageName, 0);
AppInfo app = new AppInfo();
app.setName(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
app.setIcon(p.applicationInfo.loadIcon(packageManager));
//check if the application is not an application system
Intent launchIntent = app.getLaunchIntent(context);
if(launchIntent != null && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
installedApps.add(app);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
//sort the list of applications alphabetically
if (installedApps.size() > 0) {
Collections.sort(installedApps, new Comparator() {
@Override
public int compare(final AppInfo app1, final AppInfo app2) {
return app1.getName().toLowerCase(Locale.getDefault()).compareTo(app2.getName().toLowerCase(Locale.getDefault()));
}
});
}
return installedApps;
}
return null;
}
/*
After getting those informations about installed applications, we can display them using ListViewor GridView .
Finally, to launch an installed application directly from your application, all what you need is to retrieve the launch Intent from the appInfo instance and starts the app :
*/
ArrayList installedApps = getListOfInstalledApp(this);
Intent launchIntent = installedApps.get(0).getLaunchIntent(this);
if(launchIntent != null)
startActivity(launchIntent);
]]>
< ![CDATA[
This doesn’t translate into JavaScript very easily but Lukas Morawietz made something similar : https://plus.google.com/u/0/+LukasMorawietz/posts/GUHXxS5wvAR
]]>
< ![CDATA[
Here’s the latest post and a download: https://plus.google.com/+LukasMorawietz/posts/8r8w2q7XdBZ
However this does not fill a list view as the posted code, but instead a LLContainer
]]>
< ![CDATA[
thanks guys. It never even occured to me. That Lukas Morawietz his script had to do what i had in my mind. so thanks
]]>