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

The following examples show how to use android.content.pm.PackageManager#getApplicationLabel() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Social   File: EaseUI.java    License: 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 2
Source Project: 365browser   File: BuildInfo.java    License: 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 3
/**
 * 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 Project: android-utils   File: Utils.java    License: 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 5
@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 6
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 7
Source Project: MiBandDecompiled   File: c.java    License: 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 8
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 9
Source Project: easydeviceinfo   File: EasyAppMod.java    License: 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 10
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 11
Source Project: Recovery   File: RecoveryUtil.java    License: 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 12
Source Project: AgentWeb   File: AgentWebUtils.java    License: 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 13
Source Project: oversec   File: Util.java    License: 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 14
Source Project: NewsPushMonitor   File: MiscUtil.java    License: 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 15
@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 16
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 17
Source Project: BigApp_Discuz_Android   File: Tools.java    License: 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 18
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 19
Source Project: android-notification-log   File: Util.java    License: 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 20
@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);

	}

}