private void getAllGameApp() { List<PackageInfo> apps = new ArrayList<PackageInfo>(); PackageManager pManager = getPackageManager(); // 获取手机内所有应用 List<PackageInfo> packlist = pManager.getInstalledPackages(0); for (int i = 0; i < packlist.size(); i++) { PackageInfo pak = packlist.get(i); // if()里的值如果==0则为自己装的程序,否则为系统工程自带 if ((pak.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { // 添加自己已经安装的应用程序 apps.add(pak); String appName = pManager.getApplicationLabel(pak.applicationInfo).toString(); if (MyApp.gnList.contains(appName)) { AppsItemInfo aii = new AppsItemInfo(); aii.setIcon(pManager.getApplicationIcon(pak.applicationInfo)); aii.setLabel(pManager.getApplicationLabel(pak.applicationInfo).toString()); aii.setPackageName(pak.applicationInfo.packageName); String filePath = pak.applicationInfo.publicSourceDir; aii.setSize( Util.round(new File(filePath).length() * 1.0 / (1024 * 1024), 2, BigDecimal.ROUND_UP) + "MB"); appList.add(aii); } } } }
private long addPackage(List<AppsListItem> apps, PackageStats pStats, boolean succeeded) { long cacheSize = pStats.cacheSize; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { cacheSize += pStats.externalCacheSize; } if (!succeeded || cacheSize <= 0) { return 0; } try { PackageManager packageManager = getPackageManager(); ApplicationInfo info = packageManager.getApplicationInfo(pStats.packageName, PackageManager.GET_META_DATA); apps.add( new AppsListItem( pStats.packageName, packageManager.getApplicationLabel(info).toString(), packageManager.getApplicationIcon(pStats.packageName), cacheSize)); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return cacheSize; }
public static ArrayList<Item> GetInstalledApps(Context context) { ArrayList<Item> appList = new ArrayList<Item>(); List<ApplicationInfo> myApplications; Bitmap APKIcon; Drawable icon; final PackageManager pm = context.getPackageManager(); myApplications = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : myApplications) { if (!Arrays.asList(SystemApps).contains(packageInfo.packageName)) { icon = packageInfo.loadIcon(pm); if (icon instanceof BitmapDrawable) { APKIcon = ((BitmapDrawable) icon).getBitmap(); } else { Bitmap bitmap = Bitmap.createBitmap( icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.draw(canvas); APKIcon = bitmap; } appList.add( new Item( APKIcon, (String) pm.getApplicationLabel(packageInfo), packageInfo.packageName, true)); } } return appList; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.list_item, null); holder = new ViewHolder(); holder.appName = (TextView) convertView.findViewById(R.id.app_name); holder.appIcon = (ImageView) convertView.findViewById(R.id.app_icon); holder.adProviderName = (TextView) convertView.findViewById(R.id.ad_provider_name); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } AdSource src = values[position]; PackageInfo pkg = src.packageInfo; holder.appName.setText(pm.getApplicationLabel(pkg.applicationInfo).toString()); holder.adProviderName.setText( getResources().getString(R.string.list_item_ad_framework_prefix) + ": " + src.adProvider.friendlyName); holder.appIcon.setImageDrawable(pkg.applicationInfo.loadIcon(pm)); return convertView; }
/** * check the application process name if process name is not qualified, then we think it is a * service process and we will not init SDK * * @param pID * @return */ private String getAppName(int pID) { String processName = null; ActivityManager am = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); List l = am.getRunningAppProcesses(); Iterator i = l.iterator(); PackageManager pm = appContext.getPackageManager(); while (i.hasNext()) { ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next()); try { if (info.pid == pID) { CharSequence c = pm.getApplicationLabel( pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA)); // Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ // info.processName +" Label: "+c.toString()); // processName = c.toString(); processName = info.processName; return processName; } } catch (Exception e) { // Log.d("Process", "Error>> :"+ e.toString()); } } return processName; }
/** Generate a User Agent */ public static String getUserAgent() { Context context = TramHunterApplication.getContext(); final PackageManager pm = context.getPackageManager(); String packageName = "Unknown"; String packageVersion = "Unknown"; String applicationName = "Unknown"; String androidVersion = android.os.Build.VERSION.RELEASE; if (androidVersion == null) androidVersion = "N/A"; try { packageName = context.getPackageName(); // App info ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); applicationName = (String) pm.getApplicationLabel(ai); // Package info PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, 0); packageVersion = pi.versionName; } catch (NameNotFoundException e) { return "Unknown"; } return String.format("%s/%s (Android %s)", applicationName, packageVersion, androidVersion); }
/** * 获取当前安装的dock风格包基础信息,每次重新扫描,调用者调用完后要对此返回列表清空 * * @return */ public ArrayList<StyleBaseInfo> getAllStyleBaseInfos() { ArrayList<StyleBaseInfo> mList = new ArrayList<StyleBaseInfo>(); Intent intent = new Intent(ICustomAction.ACTION_PKG_NAME); intent.addCategory(Intent.CATEGORY_DEFAULT); PackageManager pm = mContext.getPackageManager(); List<ResolveInfo> styles = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); int size = styles.size(); for (int i = 0; i < size; i++) { String appPackageName = styles.get(i).activityInfo.packageName; String appName = (String) pm.getApplicationLabel(styles.get(i).activityInfo.applicationInfo); if (null != appPackageName && null != appName) { DockStylePkgInfo info = new DockStylePkgInfo(); info.mPkgName = appPackageName; info.mStyleName = appName; mList.add(info); } } styles.clear(); styles = null; return mList; }
/** * returns list of all packages installed * * @return List<String> of all installed packages */ public List<String> getAllPackages() { settingsDB dataSrc = new settingsDB(context); dataSrc.open(); showadv = Boolean.parseBoolean(dataSrc.getSetting("showadv")); boolean tmp = false; List<String> out = new ArrayList<String>(); final PackageManager pm = context.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); allNames.clear(); allEnabled.clear(); for (ApplicationInfo packageInfo : packages) { for (int i = 0; i < MainActivity.CBAllBlackList.length; i++) { if (MainActivity.CBAllBlackList[i].contains(packageInfo.packageName)) { tmp = true; break; } } if (!tmp || showadv) { out.add(packageInfo.packageName); allNames.add(pm.getApplicationLabel(packageInfo).toString()); allEnabled.add(packageInfo.enabled); } allAdv.add(tmp); tmp = false; } dataSrc.close(); return out; }
public static String getLabel(PluginDescriptor pd) { PackageManager pm = PluginLoader.getApplication().getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(pd.getInstalledPath(), PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; appInfo.sourceDir = pd.getInstalledPath(); appInfo.publicSourceDir = pd.getInstalledPath(); String label = null; try { if (!isMainResId(appInfo.labelRes)) { label = pm.getApplicationLabel(appInfo).toString(); } } catch (Resources.NotFoundException e) { } if (label == null || label.equals(pd.getPackageName())) { // 可能设置的lable是来自宿主的资源 if (pd.getDescription() != null) { int id = ResourceUtil.getResourceId(pd.getDescription()); if (id != 0) { // 再宿主中查一次 try { label = PluginLoader.getApplication().getResources().getString(id); } catch (Resources.NotFoundException e) { } } } } if (label != null) { return label; } } return pd.getDescription(); }
private void loadData(Bundle savedInstanceState, Uri appUri) { mAppSettings = new ApiDataAccessObject(this).getApiAppSettings(appUri); // get application name and icon from package manager String appName; Drawable appIcon = null; PackageManager pm = getApplicationContext().getPackageManager(); try { ApplicationInfo ai = pm.getApplicationInfo(mAppSettings.getPackageName(), 0); appName = (String) pm.getApplicationLabel(ai); appIcon = pm.getApplicationIcon(ai); } catch (PackageManager.NameNotFoundException e) { // fallback appName = mAppSettings.getPackageName(); } mAppNameView.setText(appName); mAppIconView.setImageDrawable(appIcon); Uri accountsUri = appUri.buildUpon().appendPath(KeychainContract.PATH_ACCOUNTS).build(); Log.d(Constants.TAG, "accountsUri: " + accountsUri); Uri allowedKeysUri = appUri.buildUpon().appendPath(KeychainContract.PATH_ALLOWED_KEYS).build(); Log.d(Constants.TAG, "allowedKeysUri: " + allowedKeysUri); startListFragments(savedInstanceState, accountsUri, allowedKeysUri); }
public static String getAppName(Context c, int uid, boolean withUid) { if (sSystemUids.get(uid) != null) { return sSystemUids.get(uid); } 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; }
protected String returnLabel(String tag) { try { return (String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(tag, 0)); } catch (NameNotFoundException e) { e.printStackTrace(); return null; } }
// common utility - get intent by label, null if not found public Intent getIntentByLabel(String label) { PackageManager pm = getPackageManager(); for (ApplicationInfo packageInfo : pm.getInstalledApplications(PackageManager.GET_META_DATA)) { if (label.equals(pm.getApplicationLabel(packageInfo))) return pm.getLaunchIntentForPackage(packageInfo.packageName); } return null; }
/** * Returns the label of the specified application * * @param context The android context * @param packageName The package name * @return the label of the application */ public static String getApplicationLabel(final Context context, final String packageName) { final PackageManager pm = context.getPackageManager(); final PackageInfo pi = getPackageInfo(context, packageName); if (pi != null) { return String.valueOf(pm.getApplicationLabel(pi.applicationInfo)); } return null; }
@Nullable private CharSequence getAppLabel(@NonNull String packageName) { PackageManager pm = mContext.getPackageManager(); try { ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); return pm.getApplicationLabel(appInfo); } catch (PackageManager.NameNotFoundException e) { return null; } }
/** * 获取应用名称 * * @param context * @return */ public static String getAppName(Context context) { try { PackageManager packageManager = context.getPackageManager(); ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); return (String) packageManager.getApplicationLabel(appInfo); } catch (Exception e) { e.printStackTrace(); } return ""; }
private void showInstallNotification(ScanResult result) { if (result != null) { PackageInfo pi = null; PackageManager pm = getApplicationContext().getPackageManager(); try { pi = pm.getPackageInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String appName = pm.getApplicationLabel(pi.applicationInfo).toString(); if (result.dangerCount.equals(0)) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_icon) .setContentTitle(appName + getString(R.string.app_is_safe)) .setContentText(getString(R.string.open_app)) .setAutoCancel(true); Intent resultIntent = pm.getLaunchIntentForPackage(packageName); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_icon) .setContentTitle(appName + getString(R.string.app_unsafe)) .setContentText(getString(R.string.click_show_result)) .setAutoCancel(true); Intent resultIntent = new Intent(getBaseContext(), ResultActivity.class); // resultIntent.putExtra("CALLED_FROM", ScanService.class.getName()); Bundle bundle = new Bundle(); bundle.putParcelable("SCAN_RESULT", result); resultIntent.putExtras(bundle); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } } }
private static String getAppName(Context context) { String appName = new String(); try { final PackageManager pm = context.getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); appName = (String) pm.getApplicationLabel(ai); } catch (Exception e) { } return appName; }
public String getAppName() { PackageManager pm = context.getPackageManager(); String appName; try { ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); appName = pm.getApplicationLabel(ai).toString(); } catch (NameNotFoundException e) { appName = context.getPackageName(); } return appName; }
/** * Returns the app's name. * * @return The app's name as a String. */ public String getAppName() { Activity activity = getActivity(); try { PackageManager pm = activity.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(activity.getPackageName(), 0); return pm.getApplicationLabel(applicationInfo).toString(); } catch (NameNotFoundException exception) { return ""; } }
private String getPackageLabel(Service service, String packagename){ PackageManager packageManager = service.getPackageManager(); ApplicationInfo ai; try { ai = packageManager.getApplicationInfo( packagename, 0); } catch (final NameNotFoundException e) { ai = null; } return (String) (ai != null ? packageManager.getApplicationLabel(ai) : packagename); }
private String getApplicationName() { final PackageManager pm = getApplicationContext().getPackageManager(); ApplicationInfo ai; try { ai = pm.getApplicationInfo(this.getPackageName(), 0); } catch (final NameNotFoundException e) { ai = null; } return (String) (ai != null ? pm.getApplicationLabel(ai) : ""); }
/** 获取当前app的应用名字 */ public String getApplicationName() { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try { packageManager = getApplicationContext().getPackageManager(); applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } String applicationName = (String) packageManager.getApplicationLabel(applicationInfo); return applicationName; }
public void onCreate() { Log.w("native-activity", "onCreate"); final PackageManager pm = getApplicationContext().getPackageManager(); ApplicationInfo ai; try { ai = pm.getApplicationInfo(this.getPackageName(), 0); } catch (final NameNotFoundException e) { ai = null; } final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)"); Toast.makeText(this, applicationName, Toast.LENGTH_SHORT).show(); }
public static String e(Context var0) { PackageManager var1 = var0.getPackageManager(); ApplicationInfo var2; try { var2 = var1.getApplicationInfo(var0.getPackageName(), 0); } catch (PackageManager.NameNotFoundException var4) { var2 = null; } String var3 = (String) ((String) (var2 != null ? var1.getApplicationLabel(var2) : "")); return var3; }
public static String getApplicationName(Context context) { PackageManager packageManager = context.getApplicationContext().getPackageManager(); ApplicationInfo applicationInfo; try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (final NameNotFoundException e) { applicationInfo = null; } return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "unknown"); }
public void launchApp(String pocketName) { PackageManager packageManager = this.getPackageManager(); List<PackageInfo> packages = getAllApps(); PackageInfo pa = null; for (int i = 0; i < packages.size(); i++) { pa = packages.get(i); // 获得应用名 String appLabel = packageManager.getApplicationLabel(pa.applicationInfo).toString(); // 获得包名 String appPackage = pa.packageName; Log.d("" + i, appLabel + " " + appPackage); } newintent = packageManager.getLaunchIntentForPackage(pocketName); startActivity(newintent); }
public static ApplicationRatingInfo createApplicationInfo(Context context) { PackageManager packageManager = context.getPackageManager(); ApplicationInfo applicationInfo = null; PackageInfo packageInfo = null; try { applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0); packageInfo = packageManager.getPackageInfo(context.getApplicationInfo().packageName, 0); } catch (final PackageManager.NameNotFoundException e) { } ApplicationRatingInfo resultInfo = new ApplicationRatingInfo(); resultInfo.applicationName = packageManager.getApplicationLabel(applicationInfo).toString(); resultInfo.applicationVersionCode = packageInfo.versionCode; resultInfo.applicationVersionName = packageInfo.versionName; return resultInfo; }
/* package */ NotificationData readInboundIntent( Context context, Intent inboundIntent, ResourceIds iconIds) { final PackageManager manager = context.getPackageManager(); final String message = inboundIntent.getStringExtra("mp_message"); final String iconName = inboundIntent.getStringExtra("mp_icnm"); final String uriString = inboundIntent.getStringExtra("mp_cta"); CharSequence notificationTitle = inboundIntent.getStringExtra("mp_title"); if (message == null) { return null; } int notificationIcon = -1; if (null != iconName) { if (iconIds.knownIdName(iconName)) { notificationIcon = iconIds.idFromName(iconName); } } ApplicationInfo appInfo; try { appInfo = manager.getApplicationInfo(context.getPackageName(), 0); } catch (final NameNotFoundException e) { appInfo = null; } if (notificationIcon == -1 && null != appInfo) { notificationIcon = appInfo.icon; } if (notificationIcon == -1) { notificationIcon = android.R.drawable.sym_def_app_icon; } if (null == notificationTitle && null != appInfo) { notificationTitle = manager.getApplicationLabel(appInfo); } if (null == notificationTitle) { notificationTitle = "A message for you"; } final Intent notificationIntent = buildNotificationIntent(context, uriString); return new NotificationData(notificationIcon, notificationTitle, message, notificationIntent); }
public void sendNotification(String message, boolean isForeground) { Context appContext = HXSDKHelper.getInstance().getAppContext(); if (notificationManager == null) { notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); } try { String notifyText = message; PackageManager packageManager = appContext.getPackageManager(); String appname = (String) packageManager.getApplicationLabel(appContext.getApplicationInfo()); // notification titile String contentTitle = appname; String packageName = appContext.getApplicationInfo().packageName; Uri defaultSoundUrlUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // create and send notificaiton NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(appContext) .setSmallIcon(appContext.getApplicationInfo().icon) .setSound(defaultSoundUrlUri) .setWhen(System.currentTimeMillis()) .setAutoCancel(true); Intent msgIntent = appContext.getPackageManager().getLaunchIntentForPackage(packageName); PendingIntent pendingIntent = PendingIntent.getActivity( appContext, notifyID, msgIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentTitle(contentTitle); mBuilder.setTicker(notifyText); mBuilder.setContentText(notifyText); mBuilder.setContentIntent(pendingIntent); Notification notification = mBuilder.build(); notificationManager.notify(notifyID, notification); } catch (Exception e) { e.printStackTrace(); } }