List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:com.sxnyodot.uefqvmio207964.Util.java
static String m979p(Context context) { try {/*from www. j a v a2 s .co m*/ ApplicationInfo applicationInfo; PackageManager packageManager = context.getPackageManager(); try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (NameNotFoundException e) { applicationInfo = null; } return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "(unknown)"); } catch (Exception e2) { e2.printStackTrace(); return ""; } }
From source file:nu.yona.app.utils.AppUtils.java
/** * Has permission boolean.//from ww w.ja v a2 s.c o m * * @param context the context * @return false if user has not given permission for package access so far. */ @TargetApi(Build.VERSION_CODES.KITKAT) public static boolean hasPermission(Context context) { try { PackageManager packageManager = context.getPackageManager(); ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName); return (mode == AppOpsManager.MODE_ALLOWED); } catch (PackageManager.NameNotFoundException e) { return true; } }
From source file:com.jungle.base.utils.MiscUtils.java
public static Drawable getAppIcon() { String pkgName = MiscUtils.getPackageName(); PackageManager mgr = BaseApplication.getAppContext().getPackageManager(); try {//from w ww . j a v a 2 s .c om ApplicationInfo info = mgr.getApplicationInfo(pkgName, 0); return mgr.getApplicationIcon(info); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:com.jungle.base.utils.MiscUtils.java
public static String getAppName() { String pkgName = MiscUtils.getPackageName(); PackageManager mgr = BaseApplication.getAppContext().getPackageManager(); try {//w w w. j av a 2s. com ApplicationInfo info = mgr.getApplicationInfo(pkgName, 0); return String.valueOf(mgr.getApplicationLabel(info)); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return pkgName; }
From source file:com.noshufou.android.su.util.Util.java
public static boolean isUserOwner(Context context) { PackageManager pm = context.getPackageManager(); try {// ww w.j ava2s . c o m ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); if (ai.uid < 99999) { return true; } else { return false; } } catch (NameNotFoundException e) { Log.e(TAG, "Divided by zero..."); return false; } }
From source file:com.just.agentweb.AgentWebUtils.java
public static String getApplicationName(Context context) { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try {/*ww w . j a v a 2s .c o m*/ 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:org.deviceconnect.android.deviceplugin.kadecot.fragment.KadecotInstallFragment.java
/** * Check install Kadecot package./* www . ja va 2 s .co m*/ * * @return true : installed, false : Not install. */ private boolean isInstalledKadecotPackage() { String appId = getString(R.string.kadecot_package_name); try { PackageManager pm = getActivity().getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(appId, PackageManager.GET_META_DATA); if (appInfo != null) { return true; } } catch (PackageManager.NameNotFoundException e) { return false; } return false; }
From source file:simonlang.coastdove.core.ui.main.DetectableAppListLoader.java
@Override public ArrayList<ApplicationInfo> loadInBackground() { File directory = FileHelper.getFile(getContext(), FileHelper.Directory.PRIVATE, null, ""); String[] apps = directory.exists() ? directory.list(new FilenameFilter() { @Override// ww w .j a v a2s . c om public boolean accept(File dir, String filename) { return FileHelper.appDetectionDataExists(getContext(), filename); } }) : new String[0]; ArrayList<String> dataAsStrings = new ArrayList<>(apps.length); for (String app : apps) dataAsStrings.add(app); Collections.sort(dataAsStrings, new CollatorWrapper()); ArrayList<ApplicationInfo> data = new ArrayList<>(apps.length); for (String app : dataAsStrings) { PackageManager packageManager = getContext().getPackageManager(); try { ApplicationInfo appInfo = packageManager.getApplicationInfo(app, 0); data.add(appInfo); } catch (PackageManager.NameNotFoundException e) { Log.e("DetectableAppListLoader", "Unable to find app " + app + ": " + e.getMessage()); } } return data; }
From source file:simonlang.coastdove.usagestatistics.ui.main.AppListLoader.java
@Override public ArrayList<ApplicationInfo> loadInBackground() { AppUsageDbHelper dbHelper = new AppUsageDbHelper(getContext()); SQLiteDatabase db = dbHelper.getReadableDatabase(); String[] projection = { AppUsageContract.AppTable.COLUMN_NAME_PACKAGE }; String groupBy = AppUsageContract.AppTable.COLUMN_NAME_PACKAGE; Cursor c = db.query(AppUsageContract.AppTable.TABLE_NAME, projection, null, null, groupBy, null, null); ArrayList<ApplicationInfo> data = new ArrayList<>(c.getCount()); c.moveToFirst();// www . jav a 2 s . c o m while (!c.isAfterLast()) { String appPackageName = c.getString(0); if (appPackageName != null) { PackageManager packageManager = getContext().getPackageManager(); try { ApplicationInfo appInfo = packageManager.getApplicationInfo(appPackageName, 0); data.add(appInfo); } catch (PackageManager.NameNotFoundException e) { Log.e("AppListLoader", "Unable to find app " + appPackageName + ": " + e.getMessage()); } } c.moveToNext(); } c.close(); db.close(); return data; }
From source file:com.noshufou.android.su.util.Util.java
public static String getAppName(Context c, int uid, boolean withUid) { if (sSystemUids.get(uid) != null) { return sSystemUids.get(uid); }//from w w w . ja va2 s . c o m PackageManager pm = c.getPackageManager(); String appName = "Unknown"; String[] packages = pm.getPackagesForUid(uid); if (packages != null) { try { if (packages.length == 1) { appName = pm.getApplicationLabel(pm.getApplicationInfo(packages[0], 0)).toString(); } else if (packages.length > 1) { appName = ""; for (int i = 0; i < packages.length; i++) { appName += packages[i]; if (i < packages.length - 1) { appName += ", "; } } } } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } } else { Log.e(TAG, "Package not found for uid " + uid); } if (withUid) { appName += " (" + uid + ")"; } return appName; }