This is the first of several posts I’ve begun writing about an open source machine learning utility app for Android. Stay tuned!
I’ve been looking around for a way to launch apps using their display names (officially, the “Application Label”). It seems like a pretty straightforward thing to want to do, and I see plenty of apps that do it, but for some reason, everyone is playing their cards close to their chest (which is annoying, and part of why I wrote this post). So without further ado, a simple method that takes an application label (perhaps from user input?) and launches the desired app:
PackageManager pm = context.getPackageManager();
List<ApplicationInfo> l = pm.getInstalledApplications(PackageManager.GET_META_DATA);
String canonicalName = “”;
for (ApplicationInfo ai : l){
String n = (String)pm.getApplicationLabel(ai);
if (n.contains(name) || name.contains(n)){
canonicalName = ai.packageName;
}
}//do whatever you want with canonicalName, e.g. launch the app,
Intent app = context.getPackageManager().getLaunchIntentForPackage(canonicalName);
context.startActivity(app);
And there you have it! Share, enjoy, comment.