android.content.pm.ApplicationInfo Java Examples
The following examples show how to use
android.content.pm.ApplicationInfo.
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: IgnorePreference.java From pebble-notifier with MIT License | 6 votes |
@Override protected Void doInBackground(Void... unused) { if(pkgAppsList == null && appsList == null){ //something went really bad here return null; } if(appsList == null){ appsList = new ArrayList<ApplicationInfo>(); for(PackageInfo pkg : pkgAppsList){ appsList.add(pkg.applicationInfo); } } AppComparator comparer = new AppComparator(getContext()); Collections.sort(appsList, comparer); appsList.add(0, null); return null; }
Example #2
Source File: Util.java From styT with Apache License 2.0 | 6 votes |
public static Drawable getApkIcon(Context context, String apkPath) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; appInfo.sourceDir = apkPath; appInfo.publicSourceDir = apkPath; try { return appInfo.loadIcon(pm); } catch (OutOfMemoryError e) { // Log.e(LOG_TAG, e.toString()); } } return null; }
Example #3
Source File: ApplicationPackageManager.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public Resources getResourcesForApplication(@NonNull ApplicationInfo app) throws NameNotFoundException { if (app.packageName.equals("system")) { return mContext.mMainThread.getSystemUiContext().getResources(); } final boolean sameUid = (app.uid == Process.myUid()); final Resources r = mContext.mMainThread.getTopLevelResources( sameUid ? app.sourceDir : app.publicSourceDir, sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs, app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY, mContext.mPackageInfo); if (r != null) { return r; } throw new NameNotFoundException("Unable to open " + app.publicSourceDir); }
Example #4
Source File: Utilities.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) { final Intent intent = new Intent(action); for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) { if (info.activityInfo != null && (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String packageName = info.activityInfo.packageName; try { final Resources res = pm.getResourcesForApplication(packageName); return Pair.create(packageName, res); } catch (NameNotFoundException e) { e.printStackTrace(); } } } return null; }
Example #5
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** @hide */ @Override public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) throws NameNotFoundException { if (userId < 0) { throw new IllegalArgumentException( "Call does not support special user #" + userId); } if ("system".equals(appPackageName)) { return mContext.mMainThread.getSystemContext().getResources(); } try { ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId); if (ai != null) { return getResourcesForApplication(ai); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } throw new NameNotFoundException("Package " + appPackageName + " doesn't exist"); }
Example #6
Source File: GiftCardViewActivityTest.java From gift-card-guard with GNU General Public License v3.0 | 6 votes |
/** * Register a handler in the package manager for a image capture intent */ private void registerMediaStoreIntentHandler() { // Add something that will 'handle' the media capture intent RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager()); ResolveInfo info = new ResolveInfo(); info.isDefault = true; ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.packageName = "does.not.matter"; info.activityInfo = new ActivityInfo(); info.activityInfo.applicationInfo = applicationInfo; info.activityInfo.name = "DoesNotMatter"; Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); packageManager.addResolveInfoForIntent(intent, info); }
Example #7
Source File: ManifestUtil.java From ShareSDK with MIT License | 6 votes |
/** * 读取微信的AppKey * @param context context * @return String */ public static String getWeixinKey(Context context) { try { ApplicationInfo appInfo = context.getPackageManager() .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if(null != appInfo) { Bundle bundle = appInfo.metaData; String key = null; if(null != bundle) { key = String.valueOf(bundle.get(WEIXIN_KEY)); } if(!TextUtils.isEmpty(key)) { return key; } } } catch (Exception e) { e.printStackTrace(); } return ""; }
Example #8
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** @hide */ @Override public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) throws NameNotFoundException { if (userId < 0) { throw new IllegalArgumentException( "Call does not support special user #" + userId); } if ("system".equals(appPackageName)) { return mContext.mMainThread.getSystemContext().getResources(); } try { ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId); if (ai != null) { return getResourcesForApplication(ai); } } catch (RemoteException e) { throw new RuntimeException("Package manager has died", e); } throw new NameNotFoundException("Package " + appPackageName + " doesn't exist"); }
Example #9
Source File: App.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
public boolean isUninstallable(Context context) { if (this.isMediaInstalled(context)) { return true; } else if (this.isInstalled(context)) { PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo; try { appInfo = pm.getApplicationInfo(this.packageName, PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { return false; } // System apps aren't uninstallable. final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; return !isSystem && this.isInstalled(context); } else { return false; } }
Example #10
Source File: DevicePluginInfoFragment.java From DeviceConnect-Android with MIT License | 6 votes |
/** * Tests whether packageName exists in application list. * * @param packageName package name * @return true if packageName exists, false otherwise */ private boolean existApplicationFromPackageName(final String packageName) { if (packageName == null) { return false; } final PackageManager pm = getActivity().getPackageManager(); final int flags = PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS; final List<ApplicationInfo> installedAppList = pm.getInstalledApplications(flags); for (ApplicationInfo app : installedAppList) { if (app.packageName.equals(packageName)) { return true; } } return false; }
Example #11
Source File: HeaderFooterActivity.java From SlideAndDragListView with Apache License 2.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { CustomViewHolder cvh; if (convertView == null) { cvh = new CustomViewHolder(); convertView = LayoutInflater.from(HeaderFooterActivity.this).inflate(R.layout.item_custom_2, null); cvh.imgLogo = (ImageView) convertView.findViewById(R.id.img_item_edit); cvh.txtName = (TextView) convertView.findViewById(R.id.txt_item_edit); cvh.imgLogo2 = (ImageView) convertView.findViewById(R.id.img_item_edit2); convertView.setTag(cvh); } else { cvh = (CustomViewHolder) convertView.getTag(); } ApplicationInfo item = (ApplicationInfo) this.getItem(position); cvh.txtName.setText(item.loadLabel(getPackageManager())); cvh.imgLogo.setImageDrawable(item.loadIcon(getPackageManager())); cvh.imgLogo2.setImageDrawable(item.loadIcon(getPackageManager())); return convertView; }
Example #12
Source File: Build.java From intent_radio with MIT License | 6 votes |
public static String getBuildDate(Context context) { if ( build != null ) return build; try { ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); ZipFile file = new ZipFile(info.sourceDir); ZipEntry entry = file.getEntry("classes.dex"); long time = entry.getTime(); build = SimpleDateFormat.getInstance().format(new java.util.Date(time)); } catch (Exception e) { build = "Unknown"; } if ( debug_build(context) ) build += " [debug]"; return build; }
Example #13
Source File: DevicePluginManager.java From DeviceConnect-Android with MIT License | 6 votes |
/** * プラグインSDKのバージョンを取得します. * * @param info アプリケーション情報 * @return バージョン名 */ private VersionName getPluginSDKVersion(final ApplicationInfo info) { VersionName versionName = null; if (info.metaData != null && info.metaData.get(PLUGIN_SDK_META_DATA) != null) { PackageManager pkgMgr = mContext.getPackageManager(); XmlResourceParser xpp = info.loadXmlMetaData(pkgMgr, PLUGIN_SDK_META_DATA); try { String str = parsePluginSDKVersionName(xpp); if (str != null) { versionName = VersionName.parse(str); } } catch (Exception e) { // NOP } } if (versionName != null) { return versionName; } else { return VersionName.parse("1.0.0"); } }
Example #14
Source File: AppOpsState.java From AppOpsXposed with GNU General Public License v3.0 | 6 votes |
private AppEntry getAppEntry(final Context context, final HashMap<String, AppEntry> appEntries, final String packageName, ApplicationInfo appInfo) { AppEntry appEntry = appEntries.get(packageName); if (appEntry == null) { if (appInfo == null) { try { appInfo = mPm.getApplicationInfo(packageName, PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Unable to find info for package " + packageName); return null; } } appEntry = new AppEntry(this, appInfo); appEntry.loadLabel(context); appEntries.put(packageName, appEntry); } return appEntry; }
Example #15
Source File: ChronusResourceProvider.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
ChronusResourceProvider(@NonNull Context c, @NonNull String pkgName, @NonNull ResourceProvider defaultProvider) { this.defaultProvider = defaultProvider; try { context = c.createPackageContext( pkgName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); PackageManager manager = context.getPackageManager(); ApplicationInfo info = manager.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); providerName = manager.getApplicationLabel(info).toString(); iconDrawable = context.getApplicationInfo().loadIcon(context.getPackageManager()); } catch (Exception e) { buildDefaultInstance(c); } }
Example #16
Source File: BookmarkSettingsFragment.java From JumpGo with Mozilla Public License 2.0 | 5 votes |
@Nullable private static String getTitle(@NonNull Activity activity, @NonNull String packageName) { PackageManager pm = activity.getPackageManager(); try { ApplicationInfo info = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); CharSequence title = pm.getApplicationLabel(info); if (title != null) { return title.toString(); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
Example #17
Source File: SystemUtils.java From pandroid with Apache License 2.0 | 5 votes |
public static boolean isApplicationInstalled(String appPackage, Context context) { List<ApplicationInfo> packages; PackageManager pm; pm = context.getPackageManager(); packages = pm.getInstalledApplications(0); for (ApplicationInfo packageInfo : packages) { if (packageInfo.packageName.equals(appPackage)) return true; } return false; }
Example #18
Source File: GetApiKeyFunction.java From ANE-Crashlytics with Apache License 2.0 | 5 votes |
public FREObject call(FREContext context, FREObject[] args) { super.call(context, args); try { Activity activity = context.getActivity(); ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA); String apiKey = ai.metaData.getString("io.fabric.ApiKey"); return FREObject.newObject(apiKey); } catch (Exception e) { e.printStackTrace(); return null; } }
Example #19
Source File: AbstractAppLaunchShortcut.java From island with Apache License 2.0 | 5 votes |
private static Bitmap makeShortcutIconBitmap(final Context context, final ApplicationInfo app, final UserHandle user, final int icon) { final PackageManager pm = context.getPackageManager(); Drawable drawable = null; if (icon != 0) try { final Resources resources = pm.getResourcesForApplication(app); drawable = resources.getDrawableForDensity(icon, getDpiForLargeIcon(resources.getDisplayMetrics().densityDpi), null); } catch (final NameNotFoundException | Resources.NotFoundException ignored) {} if (drawable == null) drawable = app.loadIcon(pm); // Fallback to default density icon if (SDK_INT < O && ! Users.isOwner(user)) // Without badge icon on Android O+, since launcher will use the icon of Island as badge. drawable = pm.getUserBadgedIcon(drawable, user); return ShortcutIcons.createLargeIconBitmap(context, drawable, app.packageName); }
Example #20
Source File: DifferentMenuActivity.java From SwipeMenuListView with MIT License | 5 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(getApplicationContext(), R.layout.item_list_app, null); new ViewHolder(convertView); } ViewHolder holder = (ViewHolder) convertView.getTag(); ApplicationInfo item = getItem(position); holder.iv_icon.setImageDrawable(item.loadIcon(getPackageManager())); holder.tv_name.setText(item.loadLabel(getPackageManager())); return convertView; }
Example #21
Source File: PartnerBookmarksShim.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Checks if we need to fetch the Partner bookmarks and kicks the reading off. If reading was * attempted before, it won't do anything. */ public static void kickOffReading(Context context) { if (sIsReadingAttempted) return; sIsReadingAttempted = true; PartnerBookmarksReader reader = new PartnerBookmarksReader(context); if ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) { reader.onBookmarksRead(); return; } reader.readBookmarks(); }
Example #22
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 #23
Source File: GcmAppFragment.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); packageName = getArguments().getString(EXTRA_PACKAGE_NAME); AbstractSettingsActivity activity = (AbstractSettingsActivity) getActivity(); if (packageName != null && activity != null) { activity.setCustomBarLayout(R.layout.app_bar); try { PackageManager pm = activity.getPackageManager(); ApplicationInfo info = pm.getApplicationInfo(packageName, 0); ((ImageView) activity.findViewById(R.id.app_icon)).setImageDrawable(pm.getApplicationIcon(info)); appName = pm.getApplicationLabel(info).toString(); ((TextView) activity.findViewById(R.id.app_name)).setText(appName); View view = activity.findViewById(R.id.app_bar); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", packageName, null); intent.setData(uri); getContext().startActivity(intent); } }); view.setClickable(true); } catch (Exception e) { appName = packageName; ((TextView) activity.findViewById(R.id.app_name)).setText(packageName); } } database = new GcmDatabase(getContext()); updateAppDetails(); }
Example #24
Source File: PackageManagerHelper.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
/** * Returns whether an application is suspended as per * {@link android.app.admin.DevicePolicyManager#isPackageSuspended}. */ public static boolean isAppSuspended(ApplicationInfo info) { // The value of FLAG_SUSPENDED was reused by a hidden constant // ApplicationInfo.FLAG_PRIVILEGED prior to N, so only check for suspended flag on N // or later. if (AndroidVersion.isAtLeastNougat) { return (info.flags & ApplicationInfo.FLAG_SUSPENDED) != 0; } else { return false; } }
Example #25
Source File: AndroidUtils.java From Aria with Apache License 2.0 | 5 votes |
/** * 返回ApplicationInfo(可以通过这个读取meta-data等等) */ public static ApplicationInfo getApplicationInfo(Context context) { if (context == null) { return null; } ApplicationInfo applicationInfo = null; try { applicationInfo = context.getPackageManager() .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return applicationInfo; }
Example #26
Source File: ActivityThread.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
public final void scheduleCreateBackupAgent(ApplicationInfo app, CompatibilityInfo compatInfo, int backupMode) { CreateBackupAgentData d = new CreateBackupAgentData(); d.appInfo = app; d.compatInfo = compatInfo; d.backupMode = backupMode; queueOrSendMessage(H.CREATE_BACKUP_AGENT, d); }
Example #27
Source File: NotificationUiHelper.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
@Nullable private Drawable getAppIcon(@NonNull String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); return pm.getApplicationIcon(appInfo); } catch (PackageManager.NameNotFoundException e) { return null; } }
Example #28
Source File: PolicyManagementFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
/** * Shows an alert dialog with a list of packages with metered data disabled. */ @TargetApi(VERSION_CODES.P) private void showSetMeteredDataPrompt() { final Activity activity = getActivity(); if (activity == null || activity.isFinishing()) { return; } final List<ApplicationInfo> applicationInfos = mPackageManager.getInstalledApplications(0 /* flags */); final List<ResolveInfo> resolveInfos = new ArrayList<>(); Collections.sort(applicationInfos, new ApplicationInfo.DisplayNameComparator(mPackageManager)); for (ApplicationInfo applicationInfo : applicationInfos) { final ResolveInfo resolveInfo = new ResolveInfo(); resolveInfo.resolvePackageName = applicationInfo.packageName; resolveInfos.add(resolveInfo); } final MeteredDataRestrictionInfoAdapter meteredDataRestrictionInfoAdapter = new MeteredDataRestrictionInfoAdapter(getActivity(), resolveInfos, getMeteredDataRestrictedPkgs()); final ListView listView = new ListView(activity); listView.setAdapter(meteredDataRestrictionInfoAdapter); listView.setOnItemClickListener((parent, view, pos, id) -> meteredDataRestrictionInfoAdapter.onItemClick(parent, view, pos, id)); new AlertDialog.Builder(activity) .setTitle(R.string.metered_data_restriction) .setView(listView) .setPositiveButton(R.string.update_pkgs, meteredDataRestrictionInfoAdapter) .setNegativeButton(R.string.close, null /* Nothing to do */) .show(); }
Example #29
Source File: PackageUtil.java From android-common with Apache License 2.0 | 5 votes |
/** * 获取指定程序信息 */ public static ApplicationInfo getApplicationInfo(Context context, String pkg) { try { return context.getPackageManager().getApplicationInfo(pkg, 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
Example #30
Source File: AppApplicationUtil.java From Ency with Apache License 2.0 | 5 votes |
/** * 获取本地应用大小 * * @param context * @return 大小(字节单位) 1MB = 1024KB 1KB = 1024Byte */ public static long getAppSize(Context context) { long appSize = 0; try { ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); appSize = new File(applicationInfo.sourceDir).length(); } catch (NameNotFoundException e) { e.printStackTrace(); } return appSize; }