List of usage examples for android.content.pm PackageManager GET_UNINSTALLED_PACKAGES
int GET_UNINSTALLED_PACKAGES
To view the source code for android.content.pm PackageManager GET_UNINSTALLED_PACKAGES.
Click Source Link
From source file:com.example.android.apprestrictionenforcer.MainActivity.java
@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();/* www . j a va 2 s.c o m*/ } else { try { ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, PackageManager.GET_UNINSTALLED_PACKAGES); 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(); } } } }
From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME); PackageManager pm = getPackageManager(); ApplicationInfo appInfo;/*from w w w . j a v a 2s.com*/ try { //noinspection WrongConstant (lint is actually wrong here!) appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Failed to get ApplicationInfo for uninstalling"); } final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; if (isSystem && !isUpdate) { // Cannot remove system apps unless we're uninstalling updates throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates"); } int messageId; if (isUpdate) { messageId = R.string.uninstall_update_confirm; } else { messageId = R.string.uninstall_confirm; } // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); final AlertDialog.Builder builder = new AlertDialog.Builder(theme); builder.setTitle(appInfo.loadLabel(pm)); builder.setIcon(appInfo.loadIcon(pm)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent data = new Intent(); data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName); setResult(Activity.RESULT_OK, intent); finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setMessage(messageId); builder.create().show(); }
From source file:info.guardianproject.checkey.AppListLoader.java
/** * This is where the bulk of the work. This function is called in a * background thread and should generate a new set of data to be published * by the loader.// w w w. j av a2 s .c om */ @Override public List<AppEntry> loadInBackground() { // Retrieve all known applications List<ApplicationInfo> apps = pm.getInstalledApplications( PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS); if (apps == null) { apps = new ArrayList<ApplicationInfo>(); } // Create corresponding array of entries and load their labels List<AppEntry> entries = new ArrayList<AppEntry>(apps.size()); for (ApplicationInfo applicationInfo : apps) { AppEntry entry = new AppEntry(this, applicationInfo); entry.loadLabel(pm); entries.add(entry); } Collections.sort(entries, Comparator.ALPHA_COMPARATOR); return entries; }
From source file:net.binaryparadox.kerplapp.AppListLoader.java
/** * This is where the bulk of the work. This function is called in a * background thread and should generate a new set of data to be published * by the loader.//from w w w.j a v a 2 s . c o m */ @Override public List<AppEntry> loadInBackground() { // Retrieve all known applications List<ApplicationInfo> apps = pm.getInstalledApplications( PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS); if (apps == null) { apps = new ArrayList<ApplicationInfo>(); } final Context context = getContext(); // Create corresponding array of entries and load their labels List<AppEntry> entries = new ArrayList<AppEntry>(apps.size()); for (ApplicationInfo applicationInfo : apps) { AppEntry entry = new AppEntry(this, applicationInfo); PackageInfo packageInfo = null; // Need to load the package info to get the app version code. // We can use the repo dir, the package name and the version code to // determine if the app is already in the repo to preselect it. try { entry.loadLabel(pm); packageInfo = pm.getPackageInfo(entry.getPackageName(), 0); } catch (NameNotFoundException e) { e.printStackTrace(); continue; //We need the package info for versionCode, skip this app } catch (Exception e) { e.printStackTrace(); continue; } String apkName = packageInfo.packageName + "_" + packageInfo.versionCode + ".apk"; File apkFile = new File(FDroidApp.localRepo.repoDir, apkName); if (apkFile.exists()) entry.setEnabled(true); entries.add(entry); // Add the entry if nothing has gone wrong } Collections.sort(entries, Comparator.ALPHA_COMPARATOR); return entries; }
From source file:fr.simon.marquis.preferencesmanager.util.Utils.java
public static ArrayList<AppEntry> getApplications(Context ctx) { PackageManager pm = ctx.getPackageManager(); if (pm == null) { applications = new ArrayList<AppEntry>(); } else {/* w ww.j a v a 2 s. c om*/ boolean showSystemApps = isShowSystemApps(ctx); List<ApplicationInfo> appsInfo = pm.getInstalledApplications( PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS); if (appsInfo == null) { appsInfo = new ArrayList<ApplicationInfo>(); } List<AppEntry> entries = new ArrayList<AppEntry>(appsInfo.size()); for (ApplicationInfo a : appsInfo) { if (showSystemApps || (a.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { entries.add(new AppEntry(a, ctx)); } } Collections.sort(entries, new MyComparator()); applications = new ArrayList<AppEntry>(entries); } Log.d(TAG, "Applications: " + Arrays.toString(applications.toArray())); return applications; }
From source file:com.example.android.apprestrictionenforcer.StatusFragment.java
private void updateUi(Activity activity) { PackageManager packageManager = activity.getPackageManager(); try {//from ww w . j a v a 2 s .co m ApplicationInfo info = packageManager.getApplicationInfo(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, PackageManager.GET_UNINSTALLED_PACKAGES); 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); } }
From source file:com.cleanwiz.applock.ui.adapter.AppPagerAdapter.java
private View buildAppView(final CommLockInfo lockInfo) { View convertView = mInflater.inflate(R.layout.old_item_applock, null); ImageView ivLogo = (ImageView) convertView.findViewById(R.id.iv_app_logo); final ImageView ivTag = (ImageView) convertView.findViewById(R.id.iv_tag); View itemView = convertView.findViewById(R.id.rl_item); TextView tvName = (TextView) convertView.findViewById(R.id.tv_app_name); if (itemHeight > 0 && itemWidth > 0) { RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) itemView.getLayoutParams(); lp.height = itemHeight;//from w ww .ja va 2 s. c o m lp.width = itemWidth; } ApplicationInfo appInfo = null; try { appInfo = pkgMgr.getApplicationInfo(lockInfo.getPackageName(), PackageManager.GET_UNINSTALLED_PACKAGES); } catch (NameNotFoundException e) { e.printStackTrace(); } if (appInfo != null) { ivLogo.setImageDrawable(pkgMgr.getApplicationIcon(appInfo)); tvName.setText(pkgMgr.getApplicationLabel(appInfo)); } ivLogo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (lockInfo.getIsLocked()) { appLocker.unlockApp(lockInfo.getPackageName()); lockInfo.setIsLocked(false); } else { appLocker.lockApp(lockInfo.getPackageName()); lockInfo.setIsLocked(true); } LogUtil.d("demo3", "lock:" + lockInfo.getIsLocked()); if (lockInfo.getIsLocked()) { ivTag.setVisibility(View.VISIBLE); } else { ivTag.setVisibility(View.INVISIBLE); } } }); if (lockInfo.getIsLocked()) { ivTag.setVisibility(View.VISIBLE); } else { ivTag.setVisibility(View.INVISIBLE); } return convertView; }
From source file:com.cleanwiz.applock.ui.activity.AppLockActivity.java
private void checkLockInfos() { PackageManager pkgMgr = getPackageManager(); for (int i = lockInfos.size() - 1; i >= 0; i--) { CommLockInfo lock = lockInfos.get(i); ApplicationInfo appInfo = null;/* w ww .ja v a 2s . co m*/ try { appInfo = pkgMgr.getApplicationInfo(lock.getPackageName(), PackageManager.GET_UNINSTALLED_PACKAGES); } catch (NameNotFoundException e) { e.printStackTrace(); lockInfos.remove(lock); continue; } if (appInfo == null || pkgMgr.getApplicationIcon(appInfo) == null) { lockInfos.remove(lock); continue; } } }
From source file:org.thoughtcrime.mannycalls.ui.DialerActivity.java
public void onClickListeners() { home_btn.setOnClickListener(new View.OnClickListener() { @Override/*from w ww . j a v a2s. co m*/ public void onClick(View v) { int flags = PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.GET_UNINSTALLED_PACKAGES; List<ApplicationInfo> appsList = getApplicationContext().getPackageManager() .getInstalledApplications(flags); ApplicationInfo appInfo = null; for (int i = 0; i < appsList.size(); i++) if (appsList.get(i).toString().contains("com.mannywilson")) { appInfo = appsList.get(i); break; } if (appInfo != null) launchApp(appInfo); } }); }
From source file:com.phonegap.bossbolo.plugin.BoloPlugin.java
public void uninstallBPP() { final String packageName = "com.bossbolo.bppapp"; final CordovaPlugin currentPlugin = (CordovaPlugin) this; try {/*from ww w . java 2 s . c o m*/ ApplicationInfo info = this.cordova.getActivity().getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); new AlertDialog.Builder(this.cordova.getActivity()).setTitle("??").setMessage( "?\n ?B++???B++????B++????\n ???") .setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:" + packageName)); currentPlugin.cordova.startActivityForResult(currentPlugin, intent, 2298816); } }).show(); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }