Example usage for android.content.pm PackageManager getApplicationLabel

List of usage examples for android.content.pm PackageManager getApplicationLabel

Introduction

In this page you can find the example usage for android.content.pm PackageManager getApplicationLabel.

Prototype

public abstract CharSequence getApplicationLabel(ApplicationInfo info);

Source Link

Document

Return the label to use for this application.

Usage

From source file:com.facebook.stetho.inspector.ChromeDiscoveryHandler.java

private CharSequence getAppLabel() {
    PackageManager pm = mContext.getPackageManager();
    return pm.getApplicationLabel(mContext.getApplicationInfo());
}

From source file:dev.ukanth.ufirewall.broadcast.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;/*from  www  .  j  ava  2s .  c om*/
    }

    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Ignore application updates
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
        if (!replacing) {
            // Update the Firewall if necessary
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
            Api.applicationRemoved(context, uid);
            Api.removeCacheLabel(intent.getData().getSchemeSpecificPart(), context);
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                final PackageManager pkgmanager = context.getPackageManager();
                String label = null;
                try {
                    label = pkgmanager.getApplicationLabel(pkgmanager.getApplicationInfo(added_package, 0))
                            .toString();
                } catch (NameNotFoundException e) {
                }
                if (PackageManager.PERMISSION_GRANTED == pkgmanager
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, label);
                }
            }
        }
    }
}

From source file:android_network.hetnet.vpn_service.Util.java

public static List<String> getApplicationNames(int uid, Context context) {
    List<String> listResult = new ArrayList<>();
    if (uid == 0)
        listResult.add(context.getString(R.string.title_root));
    else if (uid == 1013)
        listResult.add(context.getString(R.string.title_mediaserver));
    else if (uid == 9999)
        listResult.add(context.getString(R.string.title_nobody));
    else {/*from  ww w  .j  a va  2 s . c om*/
        PackageManager pm = context.getPackageManager();
        String[] pkgs = pm.getPackagesForUid(uid);
        if (pkgs == null)
            listResult.add(Integer.toString(uid));
        else
            for (String pkg : pkgs)
                try {
                    ApplicationInfo info = pm.getApplicationInfo(pkg, 0);
                    listResult.add(pm.getApplicationLabel(info).toString());
                } catch (PackageManager.NameNotFoundException ignored) {
                }
        Collections.sort(listResult);
    }
    return listResult;
}

From source file:org.sufficientlysecure.keychain.remote.ui.AppSettingsFragment.java

private void updateView(AppSettings appSettings) {
    // get application name and icon from package manager
    String appName;//from w  ww . ja  va2  s.  c o  m
    Drawable appIcon = null;
    PackageManager pm = getActivity().getApplicationContext().getPackageManager();
    try {
        ApplicationInfo ai = pm.getApplicationInfo(appSettings.getPackageName(), 0);

        appName = (String) pm.getApplicationLabel(ai);
        appIcon = pm.getApplicationIcon(ai);
    } catch (NameNotFoundException e) {
        // fallback
        appName = appSettings.getPackageName();
    }
    mAppNameView.setText(appName);
    mAppIconView.setImageDrawable(appIcon);

    // advanced info: package name
    mPackageName.setText(appSettings.getPackageName());

    // advanced info: package signature SHA-256
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(appSettings.getPackageSignature());
        byte[] digest = md.digest();
        String signature = new String(Hex.encode(digest));

        mPackageSignature.setText(signature);
    } catch (NoSuchAlgorithmException e) {
        Log.e(Constants.TAG, "Should not happen!", e);
    }
}

From source file:org.sufficientlysecure.keychain.remote.ui.AppSettingsHeaderFragment.java

private void updateView(AppSettings appSettings) {
    // get application name and icon from package manager
    String appName;/* w  w w .  java  2s  .co  m*/
    Drawable appIcon = null;
    PackageManager pm = getActivity().getApplicationContext().getPackageManager();
    try {
        ApplicationInfo ai = pm.getApplicationInfo(appSettings.getPackageName(), 0);

        appName = (String) pm.getApplicationLabel(ai);
        appIcon = pm.getApplicationIcon(ai);
    } catch (NameNotFoundException e) {
        // fallback
        appName = appSettings.getPackageName();
    }
    mAppNameView.setText(appName);
    mAppIconView.setImageDrawable(appIcon);

    // advanced info: package name
    mPackageName.setText(appSettings.getPackageName());

    // advanced info: package signature SHA-256
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(appSettings.getPackageCertificate());
        byte[] digest = md.digest();
        String signature = new String(Hex.encode(digest));

        mPackageCertificate.setText(signature);
    } catch (NoSuchAlgorithmException e) {
        Log.e(Constants.TAG, "Should not happen!", e);
    }
}

From source file:com.just.agentweb.AgentWebUtils.java

public static String getApplicationName(Context context) {
    PackageManager packageManager = null;
    ApplicationInfo applicationInfo = null;
    try {/*from w w  w .  ja  v  a  2 s. c  om*/
        packageManager = context.getApplicationContext().getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        applicationInfo = null;
    }
    String applicationName = (String) packageManager.getApplicationLabel(applicationInfo);
    return applicationName;
}

From source file:me.spadival.podmode.PodNotifyService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    String notifyPackage = (String) event.getPackageName();

    if (!event.getClassName().equals(NOTIFICATION_CLASS))
        return;//from  w ww. ja v  a2 s. c  o m

    if (notifyPackage.equals(SYSTEMUI_PACKAGE) || notifyPackage.equals(THIS_PACKAGE)
            || notifyPackage.equals(ANDROID_PACKAGE))
        return;

    PackageManager pm = getPackageManager();

    String notifyAppName = null;

    try {
        notifyAppName = (String) pm.getApplicationLabel(pm.getApplicationInfo(notifyPackage, 0));
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }

    if (notifyAppName == null)
        return;

    if (notifyPackage.equals(GMAPS_PACKAGE))
        notifyAppName = getString(R.string.nav_appname);

    if (notifyPackage.equals(GNOW_PACKAGE))
        notifyAppName = "Google Now";

    List<CharSequence> textList = event.getText();

    String notifyText = "";

    if (textList.size() > 0)
        notifyText = textList.get(0).toString();

    if (notifyText.equals("") || notifyPackage.equals(GMAIL_PACKAGE)) {
        Notification eventNotification = (Notification) event.getParcelableData();

        RemoteViews notifyView = eventNotification.contentView;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        ViewGroup localView = null;
        try {
            localView = (ViewGroup) inflater.inflate(notifyView.getLayoutId(), null);
        } catch (Exception e) {
            //      e.printStackTrace();
            return;
        }

        try {

            notifyView.reapply(getApplicationContext(), localView);
        } catch (NotFoundException e) {
            //         e.printStackTrace();
        }

        View tv = localView.findViewById(android.R.id.title);
        if (tv != null && tv instanceof TextView) {
            if (notifyPackage.equals(GNOW_PACKAGE) || notifyPackage.equals(PANDORA_PACKAGE))
                notifyText = ((TextView) tv).getText().toString();
            else
                notifyAppName += ": " + ((TextView) tv).getText().toString();
        }

        if (!notifyPackage.equals(GNOW_PACKAGE)) {

            tv = localView.findViewById(16908358);
            if (tv != null && tv instanceof TextView)
                if (notifyPackage.equals(PANDORA_PACKAGE))
                    notifyAppName += ": " + ((TextView) tv).getText().toString();
                else
                    notifyText = (String) ((TextView) tv).getText().toString();
        }

        if (notifyPackage.equals(GMAIL_PACKAGE)) {
            tv = localView.findViewById(android.R.id.text2);
            if (tv != null && tv instanceof TextView)
                notifyText = (String) ((TextView) tv).getText().toString();
        }
    }

    Intent localIntent = new Intent(PodModeService.NOTIFYACTION);
    localIntent.putExtra("package", notifyPackage);
    localIntent.putExtra("appname", notifyAppName);
    localIntent.putExtra("text", notifyText);

    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);

}

From source file:org.microg.gms.ui.GcmRegisteredAppsFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    GcmData.AppInfo appInfo = appsAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position);
    MenuInflater menuInflater = getActivity().getMenuInflater();
    menuInflater.inflate(R.menu.gcm_app, menu);

    PackageManager packageManager = getContext().getPackageManager();
    try {// w  w  w  .j a v  a 2 s.c  o  m
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(appInfo.app, 0);
        menu.setHeaderTitle(packageManager.getApplicationLabel(applicationInfo));
    } catch (PackageManager.NameNotFoundException e) {
        menu.setHeaderTitle(appInfo.app);
    }
}

From source file:com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidAppDetails.java

public AndroidAppDetails(Context context, String appId) {
    this.applicationContext = context.getApplicationContext();
    try {//from  w w  w .  j  av  a 2 s . c  o  m
        PackageManager packageManager = this.applicationContext.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(this.applicationContext.getPackageName(), 0);
        ApplicationInfo appInfo = packageManager.getApplicationInfo(packageInfo.packageName, 0);

        appTitle = (String) packageManager.getApplicationLabel(appInfo);
        packageName = packageInfo.packageName;
        versionCode = String.valueOf(packageInfo.versionCode);
        versionName = packageInfo.versionName;
        this.appId = appId;
    } catch (NameNotFoundException e) {
        log.warn("Unable to get details for package " + this.applicationContext.getPackageName());
        appTitle = "Unknown";
        packageName = "Unknown";
        versionCode = "Unknown";
        versionName = "Unknown";
    }
}

From source file:org.adaway.util.ScanAdwareLoader.java

@Override
public List<Map<String, String>> loadInBackground() {
    List<PackageInfo> adPackages = getAdPackages();
    PackageManager pm = context.getPackageManager();

    List<Map<String, String>> data = new ArrayList<Map<String, String>>(adPackages.size());
    for (PackageInfo pkg : adPackages) {
        Map<String, String> attrs = new HashMap<String, String>();
        attrs.put("app_name", pm.getApplicationLabel(pkg.applicationInfo).toString());
        attrs.put("package_name", pkg.packageName);
        data.add(attrs);/*from  w w w.j  a  va 2s  .c o m*/
    }

    return data;
}