Java Code Examples for android.content.pm.PackageManager#getApplicationLabel()

The following examples show how to use android.content.pm.PackageManager#getApplicationLabel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
/**
 * Gets the name of the application that has been defined in AndroidManifest.xml
 *
 * @throws android.content.pm.PackageManager.NameNotFoundException
 **/
public static String getApplicationName(Context ctx) throws NameNotFoundException {

    if (ctx == null) {
        throw new NullPointerException("Context cannot be null");
    }

    final PackageManager packageMgr = ctx.getPackageManager();
    ApplicationInfo appInfo = null;

    try {
        appInfo = packageMgr.getApplicationInfo(ctx.getPackageName(), PackageManager.SIGNATURE_MATCH);
    } catch (final NameNotFoundException e) {
        throw new NameNotFoundException(e.getMessage());
    }

    final String applicationName = (String) (appInfo != null ? packageMgr.getApplicationLabel(appInfo) : "UNKNOWN");

    return applicationName;
}
 
Example 2
Source File: EaseUI.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * check the application process name if process name is not qualified, then we think it is a service process and we will not init SDK
 * @param pID
 * @return
 */
private String getAppName(int pID) {
    String processName = null;
    ActivityManager am = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = appContext.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
                // Log.d("Process", "Id: "+ info.pid +" ProcessName: "+
                // info.processName +"  Label: "+c.toString());
                // processName = c.toString();
                processName = info.processName;
                return processName;
            }
        } catch (Exception e) {
            // Log.d("Process", "Error>> :"+ e.toString());
        }
    }
    return processName;
}
 
Example 3
Source File: EaseUI.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * check the application process name if process name is not qualified, then we think it is a service process and we will not init SDK
 * @param pID
 * @return
 */
private String getAppName(int pID) {
    String processName = null;
    ActivityManager am = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = appContext.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
                // Log.d("Process", "Id: "+ info.pid +" ProcessName: "+
                // info.processName +"  Label: "+c.toString());
                // processName = c.toString();
                processName = info.processName;
                return processName;
            }
        } catch (Exception e) {
            // Log.d("Process", "Error>> :"+ e.toString());
        }
    }
    return processName;
}
 
Example 4
Source File: BuildInfo.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@CalledByNative
public static String getPackageLabel() {
    // Third-party code does disk read on the getApplicationInfo call. http://crbug.com/614343
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        PackageManager packageManager =
                ContextUtils.getApplicationContext().getPackageManager();
        ApplicationInfo appInfo = packageManager.getApplicationInfo(
                getPackageName(), PackageManager.GET_META_DATA);
        CharSequence label = packageManager.getApplicationLabel(appInfo);
        return label != null ? label.toString() : "";
    } catch (NameNotFoundException e) {
        return "";
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
Example 5
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
public static String getApplicationName(Context context) {
	PackageManager packageManager = null;
	ApplicationInfo applicationInfo = null;
	try {
		packageManager = context.getApplicationContext().getPackageManager();
		applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
	} catch (PackageManager.NameNotFoundException e) {
		applicationInfo = null;
	}
	String applicationName =
			(String) packageManager.getApplicationLabel(applicationInfo);
	return applicationName;
}
 
Example 6
Source File: Util.java    From android-notification-log with MIT License 5 votes vote down vote up
public static String getAppNameFromPackage(Context context, String packageName, boolean returnNull) {
	final PackageManager pm = context.getApplicationContext().getPackageManager();
	ApplicationInfo ai;
	try {
		ai = pm.getApplicationInfo(packageName, 0);
	} catch(final PackageManager.NameNotFoundException e) {
		ai = null;
	}
	if(returnNull) {
		return ai == null ? null : pm.getApplicationLabel(ai).toString();
	}
	return (String) (ai != null ? pm.getApplicationLabel(ai) : packageName);
}
 
Example 7
Source File: ComputeAppListTask.java    From exodus-android-app with GNU General Public License v3.0 5 votes vote down vote up
private ApplicationViewModel buildViewModelFromPackageInfo(PackageInfo pi,
                                                           DatabaseManager databaseManager,
                                                           PackageManager packageManager) {
    ApplicationViewModel vm = new ApplicationViewModel();

    vm.versionName = pi.versionName;
    vm.packageName = pi.packageName;
    vm.versionCode = pi.versionCode;
    vm.requestedPermissions = pi.requestedPermissions;

    if (vm.versionName != null)
        vm.report = databaseManager.getReportFor(vm.packageName, vm.versionName);
    else {
        vm.report = databaseManager.getReportFor(vm.packageName, vm.versionCode);
    }

    if (vm.report != null) {
        vm.trackers = databaseManager.getTrackers(vm.report.trackers);
    }

    try {
        vm.icon = packageManager.getApplicationIcon(vm.packageName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    vm.label = packageManager.getApplicationLabel(pi.applicationInfo);
    vm.installerPackageName = packageManager.getInstallerPackageName(vm.packageName);
    vm.isVisible = true;

    return vm;
}
 
Example 8
Source File: Tools.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 获取应用名
 * @param context
 * @return
 */
public static String getApplicationName(Context context) {  
       try {  
       	PackageManager packageManager = context.getPackageManager();  
       	ApplicationInfo applicationInfo = context.getApplicationInfo();  
       	return (String) packageManager.getApplicationLabel(applicationInfo);  
       } catch (Exception e) {  
       }  
       return "";
   }
 
Example 9
Source File: ConvenienceBuilder.java    From material-about-library with Apache License 2.0 5 votes vote down vote up
public static MaterialAboutTitleItem createAppTitleItem(Context c) {
    Context applicationContext = c.getApplicationContext();
    PackageManager packageManager = applicationContext.getPackageManager();
    ApplicationInfo applicationInfo = applicationContext.getApplicationInfo();
    CharSequence appName = packageManager.getApplicationLabel(applicationInfo);
    Drawable applicationIcon = packageManager.getApplicationIcon(applicationInfo);
    return createAppTitleItem(appName == null ? "" : appName.toString(), applicationIcon);
}
 
Example 10
Source File: BuildInfo.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@CalledByNative
public static String getPackageLabel(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        CharSequence label = packageManager.getApplicationLabel(appInfo);
        return  label != null ? label.toString() : "";
    } catch (NameNotFoundException e) {
        return "";
    }
}
 
Example 11
Source File: MiscUtil.java    From NewsPushMonitor with Apache License 2.0 5 votes vote down vote up
public static String getApplicationName(Context context, String packageName) {
    PackageManager packageManager;
    ApplicationInfo applicationInfo;
    try {
        packageManager = context.getApplicationContext().getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        return null;
    }

    String applicationName =
            (String) packageManager.getApplicationLabel(applicationInfo);
    return applicationName;
}
 
Example 12
Source File: Util.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
public static CharSequence getPackageLabel(Context ctx, String packageName) {
    PackageManager lPackageManager = ctx.getPackageManager();
    ApplicationInfo lApplicationInfo = null;
    try {
        lApplicationInfo = lPackageManager.getApplicationInfo(packageName,
                0);
    } catch (final PackageManager.NameNotFoundException e) {
        return packageName;
    }
    return lPackageManager.getApplicationLabel(lApplicationInfo);
}
 
Example 13
Source File: RecoveryUtil.java    From Recovery with Apache License 2.0 5 votes vote down vote up
public static String getAppName(Context context) {
    PackageManager packageManager = null;
    ApplicationInfo applicationInfo = null;
    if (!(context instanceof Application))
        context = context.getApplicationContext();
    try {
        packageManager = context.getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        applicationInfo = null;
    }
    CharSequence charSequence = packageManager.getApplicationLabel(applicationInfo);
    return charSequence == null ? "" : (String) charSequence;
}
 
Example 14
Source File: ApkItem.java    From DroidPlugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
ApkItem(PackageManager pm, PackageInfo info, String path) {
    try {
        icon = pm.getApplicationIcon(info.applicationInfo);
    } catch (Exception e) {
        icon = pm.getDefaultActivityIcon();
    }
    title = pm.getApplicationLabel(info.applicationInfo);
    versionName = info.versionName;
    versionCode = info.versionCode;
    apkfile = path;
    packageInfo = info;
}
 
Example 15
Source File: EasyAppMod.java    From easydeviceinfo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets app name.
 *
 * @return the app name
 */
public final String getAppName() {
  String result;
  final PackageManager pm = context.getPackageManager();
  ApplicationInfo ai = null;
  try {
    ai = pm.getApplicationInfo(context.getPackageName(), 0);
  } catch (PackageManager.NameNotFoundException e) {
    if (EasyDeviceInfo.debuggable) {
      Log.d(EasyDeviceInfo.nameOfLib, NAME_NOT_FOUND_EXCEPTION, e);
    }
  }
  result = ai != null ? (String) pm.getApplicationLabel(ai) : null;
  return CheckValidityUtil.checkValidData(result);
}
 
Example 16
Source File: FullUpdateActivity.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public String getApplicationName() {
    PackageManager packageManager = null;
    ApplicationInfo applicationInfo = null;
    try {
        packageManager = getApplicationContext().getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        applicationInfo = null;
    }
    String applicationName = (String) packageManager.getApplicationLabel(applicationInfo);
    return applicationName;
}
 
Example 17
Source File: c.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public static String g()
{
    String s;
    try
    {
        PackageManager packagemanager = d.getPackageManager();
        s = (String)packagemanager.getApplicationLabel(packagemanager.getApplicationInfo(d.getPackageName(), 0));
    }
    catch (android.content.pm.PackageManager.NameNotFoundException namenotfoundexception)
    {
        namenotfoundexception.printStackTrace();
        return "";
    }
    return s;
}
 
Example 18
Source File: Botification.java    From Botifier with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getPackageLabel(Service service, String packagename){
	PackageManager packageManager = service.getPackageManager();
	ApplicationInfo ai;
	try {
	    ai = packageManager.getApplicationInfo( packagename, 0);
	} catch (final NameNotFoundException e) {
	    ai = null;
	}
	return (String) (ai != null ? packageManager.getApplicationLabel(ai) : packagename);

}
 
Example 19
Source File: BuildInfo.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@CalledByNative
public static String getPackageLabel(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        CharSequence label = packageManager.getApplicationLabel(appInfo);
        return  label != null ? label.toString() : "";
    } catch (NameNotFoundException e) {
        return "";
    }
}
 
Example 20
Source File: ShortcutSettings.java    From Pi-Locker with GNU General Public License v2.0 2 votes vote down vote up
@Override
protected void onCreate(Bundle b) {
	super.onCreate(b);

	actionBar = getSupportActionBar();
	actionBar.setBackgroundDrawable(new ColorDrawable(0xff00BCD4));
	actionBar.setDisplayShowTitleEnabled(false);
	actionBar.setDisplayShowTitleEnabled(true);
	actionBar.setTitle(Html
			.fromHtml("<font color='#ffffff'> <b> Shortcut </b> </font>"));
	actionBar.setDisplayHomeAsUpEnabled(true);

	mContent = new LinearLayout(this);
	mContent.setOrientation(LinearLayout.VERTICAL);
	mContent.setBackgroundColor(Color.WHITE);

	setContentView(mContent);

	for (int i = 0; i < CAPACITY; i++) {

		final int bb = i;

		final ShortCut txt = new ShortCut(getBaseContext(), null);

		final Handler h = new Handler();

		View v = new View(ShortcutSettings.this);

		LayoutParams vv = new LayoutParams(LayoutParams.MATCH_PARENT, 1);

		v.setBackgroundColor(0x33000000);
		v.setPadding(0, 5, 0, 5);

		mContent.addView(v, vv);

		String Sys = Settings.System.getString(getContentResolver(), "PiSC" + bb);
		ApplicationInfo ai = null;
		PackageManager pm;
		pm = getPackageManager();

		if (Sys != null) {

			try {

				ai = pm.getApplicationInfo(Sys, 0);
				String App_Name = (String) pm.getApplicationLabel(ai);
				Drawable Icon = pm.getApplicationIcon(ai);
				txt.setName(App_Name);
				txt.setImage(Icon);

			} catch (NameNotFoundException e) {

				e.printStackTrace();
			}

		}

		else if (Sys == null) {

		}

		txt.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {

				Toast.makeText(getApplicationContext(), "Please Wait..",
						Toast.LENGTH_LONG).show();

				PickerApp.setCurSor(bb);

				startActivity(new Intent(ShortcutSettings.this,
						PickerApp.class));

			}
		});

		mContent.addView(txt);

	}

}