/** * Retrieve the current textual label associated with this resolution. This will call back on the * given PackageManager to load the label from the application. * * @param pm A PackageManager from which the label can be loaded; usually the PackageManager from * which you originally retrieved this item. * @return Returns a CharSequence containing the resolutions's label. If the item does not have a * label, its name is returned. */ public CharSequence loadLabel(PackageManager pm) { if (nonLocalizedLabel != null) { return nonLocalizedLabel; } CharSequence label; if (resolvePackageName != null && labelRes != 0) { label = pm.getText(resolvePackageName, labelRes, null); if (label != null) { return label.toString().trim(); } } ComponentInfo ci = getComponentInfo(); ApplicationInfo ai = ci.applicationInfo; if (labelRes != 0) { label = pm.getText(ci.packageName, labelRes, ai); if (label != null) { return label.toString().trim(); } } CharSequence data = ci.loadLabel(pm); // Make the data safe if (data != null) data = data.toString().trim(); return data; }
/** * @param context * @return */ public static String getApplicationName(final Context context) { String name = null; try { final PackageManager packagemanager = context.getPackageManager(); final PackageInfo packageinfo = packagemanager.getPackageInfo(context.getPackageName(), 0); name = packageinfo.applicationInfo.loadLabel(packagemanager).toString() + "(" + packageinfo.packageName + ")"; } catch (Exception x) { DBG.m(x); } return name; }
private boolean isPackageUnavailable(PackageManager pm) { try { return pm.getPackageInfo(packageName, 0) == null; } catch (NameNotFoundException ex) { return true; } }
public WorkflowInstance build() { NodeRef packageRef = packageMgr.create(packageNode); params.put(WorkflowModel.ASSOC_PACKAGE, packageRef); WorkflowPath path = workflowService.startWorkflow(definition.getId(), params); signalStartTask(path); return path.getInstance(); }
/** @hide */ @Override public Drawable loadDefaultIcon(PackageManager pm) { if ((flags & FLAG_EXTERNAL_STORAGE) != 0 && isPackageUnavailable(pm)) { return Resources.getSystem() .getDrawable(com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon); } return pm.getDefaultActivityIcon(); }
public static ApplicationInfo findApplication(Context context, String regex, boolean system) { ApplicationInfo info = null; if (context != null) { String[] regs = regex.split("\\|"); // 0:start, 1:end, 2:contain PackageManager pm = context.getPackageManager(); List<ApplicationInfo> list = null; try { list = pm.getInstalledApplications(0); } catch (Exception e) { } boolean match = true; if (list != null && list.size() != 0) { String pkgName = ""; for (ApplicationInfo pn : list) { if (system && (!pn.publicSourceDir.contains("/system/app") && !pn.publicSourceDir.contains("/system/priv-app"))) { continue; } pkgName = pn.packageName; if (!regs[0].trim().equals("")) { match = pkgName.startsWith(regs[0].trim()); } if (match && !regs[1].trim().equals("")) { match = pkgName.endsWith(regs[1].trim()); } if (match && !regs[2].trim().equals("")) { match = pkgName.contains(regs[2].trim()); } if (match) { try { info = pm.getApplicationInfo(pkgName, 0); } catch (Exception e) { } if (info != null) { break; } } } } } return info; }
/** * Retrieve the current graphical icon associated with this resolution. This will call back on the * given PackageManager to load the icon from the application. * * @param pm A PackageManager from which the icon can be loaded; usually the PackageManager from * which you originally retrieved this item. * @return Returns a Drawable containing the resolution's icon. If the item does not have an icon, * the default activity icon is returned. */ public Drawable loadIcon(PackageManager pm) { Drawable dr; if (resolvePackageName != null && icon != 0) { dr = pm.getDrawable(resolvePackageName, icon, null); if (dr != null) { return dr; } } ComponentInfo ci = getComponentInfo(); ApplicationInfo ai = ci.applicationInfo; if (icon != 0) { dr = pm.getDrawable(ci.packageName, icon, ai); if (dr != null) { return dr; } } return ci.loadIcon(pm); }
/** * Retrieve the icon associated with this object. If the object does not have a icon, null will be * returned, in which case you will probably want to load the icon from the underlying resolved * info for the Intent. */ public Drawable loadIcon(PackageManager pm) { if (mIcon != 0 && mSourcePackage != null) { Drawable icon = pm.getDrawable(mSourcePackage, mIcon, null); if (icon != null) { return icon; } } return null; }
/** * Retrieve the textual description of the application. This will call back on the given * PackageManager to load the description from the application. * * @param pm A PackageManager from which the label can be loaded; usually the PackageManager from * which you originally retrieved this item. * @return Returns a CharSequence containing the application's description. If there is no * description, null is returned. */ public CharSequence loadDescription(PackageManager pm) { if (descriptionRes != 0) { CharSequence label = pm.getText(packageName, descriptionRes, this); if (label != null) { return label; } } return null; }
public static long backupExists(ApplicationInfo in){ PackageInfo i = null; String PATH = Environment.getExternalStorageDirectory().getPath(); try { i = nPManager.getPackageInfo(in.packageName, 0); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } File file = new File(PATH + "/File Quest/AppBackup"); if( file.exists() && new File(PATH + "/File Quest").exists()){ for(File f:file.listFiles()){ String out_file = nPManager.getApplicationLabel(in) + "-v"+i.versionName + ".apk"; if(f.getName().equals(out_file)){ return f.lastModified(); } } } return 0; }
private Bitmap getAppDrawable(String path) throws OutOfMemoryError { Bitmap bitsat; try { PackageManager pm = mContext.getPackageManager(); PackageInfo pi = pm.getPackageArchiveInfo(path, 0); // // the secret are these two lines.... pi.applicationInfo.sourceDir = path; pi.applicationInfo.publicSourceDir = path; // // Drawable d = pi.applicationInfo.loadIcon(pm); Bitmap d1 = null; d1 = ((BitmapDrawable) d).getBitmap(); bitsat = d1; } catch (Exception e) { Drawable apk = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_apk_grid); Bitmap apk1 = ((BitmapDrawable) apk).getBitmap(); bitsat = apk1; } return bitsat; }
/** * Retrieve the label associated with this object. If the object does not have a label, null will * be returned, in which case you will probably want to load the label from the underlying * resolved info for the Intent. */ public CharSequence loadLabel(PackageManager pm) { if (mNonLocalizedLabel != null) { return mNonLocalizedLabel; } if (mLabelRes != 0 && mSourcePackage != null) { CharSequence label = pm.getText(mSourcePackage, mLabelRes, null); if (label != null) { return label; } } return null; }
String[] getPluginDirectories() { ArrayList<String> directories = new ArrayList<String>(); PackageManager pm = this.mAppContext.getPackageManager(); List<ResolveInfo> plugins = pm.queryIntentServices( new Intent(PLUGIN_ACTION), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA); synchronized (mPackageInfoCache) { // clear the list of existing packageInfo objects mPackageInfoCache.clear(); for (ResolveInfo info : plugins) { // retrieve the plugin's service information ServiceInfo serviceInfo = info.serviceInfo; if (serviceInfo == null) { Log.w(LOGTAG, "Ignore bad plugin"); continue; } Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName); // retrieve information from the plugin's manifest PackageInfo pkgInfo; try { pkgInfo = pm.getPackageInfo( serviceInfo.packageName, PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES); } catch (Exception e) { Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName); continue; } if (pkgInfo == null) { Log.w( LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Could not load package information."); continue; } /* * find the location of the plugin's shared library. The default * is to assume the app is either a user installed app or an * updated system app. In both of these cases the library is * stored in the app's data directory. */ String directory = pkgInfo.applicationInfo.dataDir + "/lib"; final int appFlags = pkgInfo.applicationInfo.flags; final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; // preloaded system app with no user updates if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) { directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName; } // check if the plugin has the required permissions String permissions[] = pkgInfo.requestedPermissions; if (permissions == null) { Log.w( LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission."); continue; } boolean permissionOk = false; for (String permit : permissions) { if (PLUGIN_PERMISSION.equals(permit)) { permissionOk = true; break; } } if (!permissionOk) { Log.w( LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission (2)."); continue; } // check to ensure the plugin is properly signed Signature signatures[] = pkgInfo.signatures; if (signatures == null) { Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed."); continue; } // determine the type of plugin from the manifest if (serviceInfo.metaData == null) { Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined"); continue; } String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE); if (!TYPE_NATIVE.equals(pluginType)) { Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType); continue; } try { Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name); // TODO implement any requirements of the plugin class here! boolean classFound = true; if (!classFound) { Log.e( LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class."); continue; } } catch (NameNotFoundException e) { Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName); continue; } catch (ClassNotFoundException e) { Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name); continue; } // if all checks have passed then make the plugin available mPackageInfoCache.add(pkgInfo); directories.add(directory); } } return directories.toArray(new String[directories.size()]); }
public void addPackageItems(List<NodeRef> items) { packageMgr.addItems(items); }