Java Code Examples for android.content.pm.ApplicationInfo#FLAG_INSTALLED
The following examples show how to use
android.content.pm.ApplicationInfo#FLAG_INSTALLED .
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: LauncherAppsCompatVL.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
@Override public ApplicationInfo getApplicationInfo(String packageName, int flags, UserHandle user) { final boolean isPrimaryUser = Process.myUserHandle().equals(user); if (!isPrimaryUser && (flags == 0)) { // We are looking for an installed app on a secondary profile. Prior to O, the only // entry point for work profiles is through the LauncherActivity. List<LauncherActivityInfo> activityList = mLauncherApps.getActivityList(packageName, user); return activityList.size() > 0 ? activityList.get(0).getApplicationInfo() : null; } try { ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(packageName, flags); // There is no way to check if the app is installed for managed profile. But for // primary profile, we can still have this check. if (isPrimaryUser && ((info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) || !info.enabled) { return null; } return info; } catch (PackageManager.NameNotFoundException e) { // Package not found return null; } }
Example 2
Source File: UserPackage.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Return {@code true} if the package is installed and not hidden */ public boolean isInstalledPackage() { if (mPackageInfo == null) return false; return (((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) != 0) && ((mPackageInfo.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_HIDDEN) == 0)); }
Example 3
Source File: StatusFragment.java From enterprise-samples with Apache License 2.0 | 5 votes |
private void updateUi(Activity activity) { PackageManager packageManager = activity.getPackageManager(); try { int packageFlags; if (Build.VERSION.SDK_INT < 24) { //noinspection deprecation packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; } else { packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; } ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, packageFlags); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE); if ((info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) { if (!devicePolicyManager.isApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(activity), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is ready to enforce restrictions // This is unlikely to happen in this sample as unhideApp() handles it. mListener.onStatusUpdated(); } else { // The app is installed but hidden in this profile mTextStatus.setText(R.string.status_not_activated); mButtonUnhide.setVisibility(View.VISIBLE); } } else { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } } catch (PackageManager.NameNotFoundException e) { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } }
Example 4
Source File: BasicManagedProfileFragment.java From enterprise-samples with Apache License 2.0 | 5 votes |
/** * Checks if the application is available in this profile. * * @param packageName The package name * @return True if the application is available in this profile. */ private boolean isApplicationEnabled(String packageName) { Activity activity = getActivity(); PackageManager packageManager = activity.getPackageManager(); try { int packageFlags; if(Build.VERSION.SDK_INT < 24){ //noinspection deprecation packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; }else{ packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; } ApplicationInfo applicationInfo = packageManager.getApplicationInfo( packageName, packageFlags); // Return false if the app is not installed in this profile if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) { return false; } // Check if the app is not hidden in this profile DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE); return !devicePolicyManager.isApplicationHidden( BasicDeviceAdminReceiver.getComponentName(activity), packageName); } catch (PackageManager.NameNotFoundException e) { return false; } }
Example 5
Source File: LauncherAppsCompatVO.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@Override public ApplicationInfo getApplicationInfo(String packageName, int flags, UserHandle user) { try { // TODO: Temporary workaround until the API signature is updated if (false) { throw new PackageManager.NameNotFoundException(); } ApplicationInfo info = mLauncherApps.getApplicationInfo(packageName, flags, user); return (info.flags & ApplicationInfo.FLAG_INSTALLED) == 0 || !info.enabled ? null : info; } catch (PackageManager.NameNotFoundException e) { return null; } }
Example 6
Source File: StatusFragment.java From android-AppRestrictionEnforcer with Apache License 2.0 | 5 votes |
private void updateUi(Activity activity) { PackageManager packageManager = activity.getPackageManager(); try { int packageFlags; if (Build.VERSION.SDK_INT < 24) { //noinspection deprecation packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; } else { packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; } ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, packageFlags); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE); if ((info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) { if (!devicePolicyManager.isApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(activity), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is ready to enforce restrictions // This is unlikely to happen in this sample as unhideApp() handles it. mListener.onStatusUpdated(); } else { // The app is installed but hidden in this profile mTextStatus.setText(R.string.status_not_activated); mButtonUnhide.setVisibility(View.VISIBLE); } } else { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } } catch (PackageManager.NameNotFoundException e) { // Need to reinstall the sample app mTextStatus.setText(R.string.status_need_reinstall); mButtonUnhide.setVisibility(View.GONE); } }
Example 7
Source File: BasicManagedProfileFragment.java From android-BasicManagedProfile with Apache License 2.0 | 5 votes |
/** * Checks if the application is available in this profile. * * @param packageName The package name * @return True if the application is available in this profile. */ private boolean isApplicationEnabled(String packageName) { Activity activity = getActivity(); PackageManager packageManager = activity.getPackageManager(); try { int packageFlags; if(Build.VERSION.SDK_INT < 24){ //noinspection deprecation packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; }else{ packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; } ApplicationInfo applicationInfo = packageManager.getApplicationInfo( packageName, packageFlags); // Return false if the app is not installed in this profile if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) { return false; } // Check if the app is not hidden in this profile DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE); return !devicePolicyManager.isApplicationHidden( BasicDeviceAdminReceiver.getComponentName(activity), packageName); } catch (PackageManager.NameNotFoundException e) { return false; } }
Example 8
Source File: Apps.java From deagle with Apache License 2.0 | 5 votes |
/** Check whether specified app is installed in current user, even if hidden by system (Android 5+). */ public @CheckResult boolean isInstalledInCurrentUser(final String pkg) { try { @SuppressWarnings("deprecation") final ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(pkg, GET_UNINSTALLED_PACKAGES); return (info.flags & ApplicationInfo.FLAG_INSTALLED) != 0; } catch (final NameNotFoundException e) { return false; } }
Example 9
Source File: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static boolean isInstalled(@Nullable ApplicationInfo ai) { return (ai != null) && ai.enabled && (ai.flags & ApplicationInfo.FLAG_INSTALLED) != 0; }
Example 10
Source File: MainActivity.java From enterprise-samples with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (null == savedInstanceState) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); PackageManager packageManager = getPackageManager(); if (!devicePolicyManager.isProfileOwnerApp(getApplicationContext().getPackageName())) { // If the managed profile is not yet set up, we show the setup screen. showSetupProfile(); } else { try { int packageFlags; if (Build.VERSION.SDK_INT < 24) { //noinspection deprecation packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; } else { packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; } ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, packageFlags); if (0 == (info.flags & ApplicationInfo.FLAG_INSTALLED)) { // Need to reinstall the sample app showStatusProfile(); } else if (devicePolicyManager.isApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(this), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is installed but hidden in this profile showStatusProfile(); } else { // Everything is clear; show the main screen showMainFragment(); } } catch (PackageManager.NameNotFoundException e) { showStatusProfile(); } } } }
Example 11
Source File: MainActivity.java From android-AppRestrictionEnforcer with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_real); if (null == savedInstanceState) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); PackageManager packageManager = getPackageManager(); if (!devicePolicyManager.isProfileOwnerApp(getApplicationContext().getPackageName())) { // If the managed profile is not yet set up, we show the setup screen. showSetupProfile(); } else { try { int packageFlags; if (Build.VERSION.SDK_INT < 24) { //noinspection deprecation packageFlags = PackageManager.GET_UNINSTALLED_PACKAGES; } else { packageFlags = PackageManager.MATCH_UNINSTALLED_PACKAGES; } ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, packageFlags); if (0 == (info.flags & ApplicationInfo.FLAG_INSTALLED)) { // Need to reinstall the sample app showStatusProfile(); } else if (devicePolicyManager.isApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(this), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is installed but hidden in this profile showStatusProfile(); } else { // Everything is clear; show the main screen showMainFragment(); } } catch (PackageManager.NameNotFoundException e) { showStatusProfile(); } } } }
Example 12
Source File: AppInfo.java From island with Apache License 2.0 | votes |
public boolean isInstalled() { return (flags & ApplicationInfo.FLAG_INSTALLED) != 0; }