Android Context Get getApplicationName(Context ctx)

Here you can find the source of getApplicationName(Context ctx)

Description

Finds current application name

License

Open Source License

Parameter

Parameter Description
ctx context of application

Return

Name of current application

Declaration

public static String getApplicationName(Context ctx) 

Method Source Code

//package com.java2s;
//  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of

import android.content.Context;

import android.content.pm.ApplicationInfo;

import android.content.pm.PackageManager;

public class Main {
    /**//from w ww.  ja v a2s  . com
     * Finds current application name
     * @param ctx context of application
     * @return Name of current application
     */
    public static String getApplicationName(Context ctx) {
        ApplicationInfo ai;
        try {
            Context appContext = ctx.getApplicationContext();
            assert appContext != null;
            final PackageManager pm = appContext.getPackageManager();
            assert pm != null;
            ai = pm.getApplicationInfo(ctx.getPackageName(), 0);
            return (String) (ai != null ? pm.getApplicationLabel(ai)
                    : "(unknown)");
        } catch (Exception ignored) {
        }
        return null;
    }
}

Related

  1. getAppKey(Context context)
  2. getAppVersion(Context context)
  3. getApplicationInfos(Context context)
  4. getApplicationMemoryClass(@Nonnull Context context)
  5. getApplicationMetaData(Context context, String key)
  6. getAsset(@Nonnull Context context, @Nonnull String path)
  7. getAsset(@Nonnull Context context, @Nonnull String path)
  8. getAuthorityFromPermission(Context context, String permission)
  9. getBatteryUsageInfo(Context context)