Here you can find the source of getApplicationName(Context ctx)
Parameter | Description |
---|---|
ctx | context of application |
public static String getApplicationName(Context ctx)
//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; } }