List of usage examples for android.content.pm ApplicationInfo loadLabel
public @NonNull CharSequence loadLabel(@NonNull PackageManager pm)
From source file:Main.java
public static String getAppName(Context context) { ApplicationInfo var1 = context.getApplicationInfo(); return var1.loadLabel(context.getPackageManager()).toString(); }
From source file:Main.java
public static String loadAppName(Context context, String pkgName) { try {//w w w .java 2 s.co m PackageManager pm = context.getPackageManager(); ApplicationInfo info = pm.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); return info.loadLabel(pm).toString(); } catch (Exception e) { } return ""; }
From source file:Main.java
/** * Get app name//w w w .j a v a 2s . co m * * @param context * @param packageName * @return */ public static String getAppName(Context context, String packageName) { try { PackageManager pm = context.getPackageManager(); ApplicationInfo info = pm.getApplicationInfo(packageName, 0); return info.loadLabel(pm).toString(); } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getAppLable(Context context, String pkgName) { try {/* w w w . ja v a 2s . c o m*/ PackageManager pm = context.getPackageManager(); ApplicationInfo info = pm.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); return info.loadLabel(pm).toString(); } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:com.example.dashclock.examplehost.ExampleHostActivity.java
private static String packagesNameListToAppNameString(Context context, List<String> pkgs) { StringBuilder sb = new StringBuilder(); final PackageManager pm = context.getPackageManager(); for (String pkg : pkgs) { sb.append("\n\n\t"); try {/*from w w w.j a v a 2 s .com*/ ApplicationInfo pi = pm.getApplicationInfo(pkg, 0); CharSequence name = pi.loadLabel(pm); if (name == null) { sb.append(pkg); } else { sb.append(name); } } catch (PackageManager.NameNotFoundException ex) { sb.append(pkg); } } return sb.toString(); }
From source file:simonlang.coastdove.core.ui.add_app.AppListLoader.java
@Override public ArrayList<ApplicationInfo> loadInBackground() { final PackageManager packageManager = getContext().getPackageManager(); List<PackageInfo> packageInfos = packageManager.getInstalledPackages(PackageManager.GET_ACTIVITIES); ArrayList<ApplicationInfo> data = new ArrayList<>(); for (int i = 0; i < packageInfos.size(); ++i) { PackageInfo packageInfo = packageInfos.get(i); data.add(packageInfo.applicationInfo); }// w ww. j a v a 2s . c om Collections.sort(data, new Comparator<ApplicationInfo>() { @Override public int compare(ApplicationInfo lhs, ApplicationInfo rhs) { String lhsAppName = lhs.loadLabel(packageManager).toString(); String rhsAppName = rhs.loadLabel(packageManager).toString(); return lhsAppName.compareTo(rhsAppName); } }); return data; }
From source file:org.deviceconnect.android.observer.fragment.WarningDialogFragment.java
/** * ????.// ww w . j a va2s . co m * * @param packageName ??? * @return ?? */ private String getAppName(final String packageName) { PackageManager pm = getActivity().getPackageManager(); final List<ApplicationInfo> appInfoList = pm.getInstalledApplications( PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS); for (ApplicationInfo ai : appInfoList) { String appName = ai.loadLabel(pm).toString(); if (ai.packageName.equals(packageName)) { return appName; } } return "NoName"; }
From source file:eu.musesproject.client.contextmonitoring.sensors.DeviceProtectionSensor.java
public boolean isTrustedAntiVirInstalled() { PackageManager packageManager = context.getPackageManager(); List<ApplicationInfo> installedApps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo appInfo : installedApps) { String appName = appInfo.loadLabel(packageManager).toString(); for (String trustedAVName : trustedAVs) { if (trustedAVName.equals(appName)) { return true; }// w w w . j av a2 s. co m } } return false; }
From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java
private void setupSimplePreferencesScreen() { addPreferencesFromResource(R.xml.pref_application); applicationCategory = (PreferenceCategory) findPreference("header_application"); // Listen for check/uncheck all tap findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override//from w w w .ja va 2 s . co m public boolean onPreferenceChange(Preference arg0, Object arg1) { for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) { // Uncheck or check all items ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1); } return true; } }); class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> { private PackageManager packageManager; @Override protected void onPreExecute() { progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true); } @Override protected List<ApplicationInfo> doInBackground(String... notif) { packageManager = getApplicationContext().getPackageManager(); // Comparator used to sort applications by name class CustomComparator implements Comparator<ApplicationInfo> { @Override public int compare(ApplicationInfo arg0, ApplicationInfo arg1) { return arg0.loadLabel(packageManager).toString() .compareTo(arg1.loadLabel(packageManager).toString()); } } // Get installed applications Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ApplicationInfo> appList = getApplicationContext().getPackageManager() .getInstalledApplications(PackageManager.GET_META_DATA); // Sort by application name Collections.sort(appList, new CustomComparator()); return appList; } @Override protected void onPostExecute(List<ApplicationInfo> result) { // Add each application to screen for (ApplicationInfo appInfo : result) { CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this); c.setTitle(appInfo.loadLabel(packageManager).toString()); c.setSummary(appInfo.packageName); c.setIcon(appInfo.loadIcon(packageManager)); c.setKey(appInfo.packageName); c.setChecked(true); c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // On tap, show an enabled/disabled notification on the desktop Object[] notif = new Object[3]; if (arg1.toString().equals("true")) { notif[0] = arg0.getTitle().toString() + " notifications enabled"; notif[1] = "via LinConnect"; notif[2] = arg0.getIcon(); } else { notif[0] = arg0.getTitle().toString() + " notifications disabled"; notif[1] = "via LinConnect"; notif[2] = arg0.getIcon(); } new TestTask().execute(notif); return true; } }); applicationCategory.addPreference(c); } progressDialog.dismiss(); } } new ApplicationTask().execute(); }
From source file:com.oasisfeng.nevo.decorators.bundle.BundleDecorator.java
private String getSourceNames(final Set<String> pkgs) { final PackageManager pm = getPackageManager(); final StringBuilder names = new StringBuilder(); for (final String pkg : pkgs) try {/*from w w w . j a v a2s . co m*/ final ApplicationInfo app_info = pm.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES); names.append(", ").append(app_info.loadLabel(pm)); } catch (final NameNotFoundException ignored) { } // TODO: Packages from other user profiles? return names.substring(2); }