public void onCreate(Activity activity, Bundle savedInstanceState) { PackageManager manager = activity.getBaseContext().getPackageManager(); String[] keys = {"tapjoyAppID", "tapjoySecretKey"}; try { Bundle meta = manager.getApplicationInfo( activity.getApplicationContext().getPackageName(), PackageManager.GET_META_DATA) .metaData; for (String k : keys) { if (meta.containsKey(k)) { manifestKeyMap.put(k, meta.get(k).toString()); } } } catch (Exception e) { logger.log("Exception while loading manifest keys:", e); } String tapJoyAppID = manifestKeyMap.get("tapjoyAppID"); String tapJoySecretKey = manifestKeyMap.get("tapjoySecretKey"); logger.log("{tapjoy} Installing for appID:", tapJoyAppID); // Enables logging to the console. // TapjoyLog.enableLogging(true); // Connect with the Tapjoy server. TapjoyConnect.requestTapjoyConnect(_ctx, tapJoyAppID, tapJoySecretKey); }
/** Build {@link UidDetail} object, blocking until all {@link Drawable} lookup is finished. */ private UidDetail buildUidDetail(int uid) { final Resources res = mContext.getResources(); final PackageManager pm = mContext.getPackageManager(); final UidDetail detail = new UidDetail(); detail.label = pm.getNameForUid(uid); detail.icon = pm.getDefaultActivityIcon(); // handle special case labels switch (uid) { case android.os.Process.SYSTEM_UID: detail.label = res.getString(R.string.process_kernel_label); detail.icon = pm.getDefaultActivityIcon(); return detail; case TrafficStats.UID_REMOVED: detail.label = res.getString(R.string.data_usage_uninstalled_apps); detail.icon = pm.getDefaultActivityIcon(); return detail; case TrafficStats.UID_TETHERING: final ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); detail.label = res.getString(Utils.getTetheringLabel(cm)); detail.icon = pm.getDefaultActivityIcon(); return detail; } // otherwise fall back to using packagemanager labels final String[] packageNames = pm.getPackagesForUid(uid); final int length = packageNames != null ? packageNames.length : 0; try { if (length == 1) { final ApplicationInfo info = pm.getApplicationInfo(packageNames[0], 0); detail.label = info.loadLabel(pm).toString(); detail.icon = info.loadIcon(pm); } else if (length > 1) { detail.detailLabels = new CharSequence[length]; for (int i = 0; i < length; i++) { final String packageName = packageNames[i]; final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0); final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); detail.detailLabels[i] = appInfo.loadLabel(pm).toString(); if (packageInfo.sharedUserLabel != 0) { detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo) .toString(); detail.icon = appInfo.loadIcon(pm); } } } } catch (NameNotFoundException e) { } if (TextUtils.isEmpty(detail.label)) { detail.label = Integer.toString(uid); } return detail; }
private static boolean isBaiduRom() { boolean ret = false; try { ApplicationInfo infoService = pm.getApplicationInfo("com.baidu.bsf.service", 0); ApplicationInfo infoSystem = pm.getApplicationInfo("com.baidu.bsf.system", 0); ret = (infoService != null && infoSystem != null); } catch (Exception e) { } return ret; }
private void refreshList() { if (iFavoritesService == null) { Log.i(TAG, "refreshList iFavoritesService null"); return; } try { List<String> favoritesPackageList = iFavoritesService.getFavoritesMap(); mAppInfoList.clear(); for (String packageName : favoritesPackageList) { ApplicationInfo applicationInfo; try { applicationInfo = mPackageManager.getApplicationInfo(packageName, 0); FavoritesAppInfo appInfo = new FavoritesAppInfo(); appInfo.packageName = applicationInfo.packageName; appInfo.appName = applicationInfo.loadLabel(mPackageManager).toString(); appInfo.appIntent = mPackageManager.getLaunchIntentForPackage(applicationInfo.packageName); appInfo.appIcon = applicationInfo.loadIcon(mPackageManager); mAppInfoList.add(appInfo); } catch (NameNotFoundException e) { e.printStackTrace(); } } } catch (RemoteException e) { e.printStackTrace(); } Intent intent = new Intent(FavoritesModel.ACTION_LOAD_FAVOTITE_SUCCESS); mContext.sendBroadcast(intent); }
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; }
/** * As of ICE_CREAM_SANDWICH we are automatically adding padding to widgets targeting * ICE_CREAM_SANDWICH and higher. The new widget design guidelines strongly recommend that widget * developers do not add extra padding to their widgets. This will help achieve consistency among * widgets. * * <p>Note: this method is only needed by developers of AppWidgetHosts. The method is provided in * order for the AppWidgetHost to account for the automatic padding when computing the number of * cells to allocate to a particular widget. * * @param context the current context * @param component the component name of the widget * @param padding Rect in which to place the output, if null, a new Rect will be allocated and * returned * @return default padding for this widget, in pixels */ public static Rect getDefaultPaddingForWidget( Context context, ComponentName component, Rect padding) { PackageManager packageManager = context.getPackageManager(); ApplicationInfo appInfo; if (padding == null) { padding = new Rect(0, 0, 0, 0); } else { padding.set(0, 0, 0, 0); } try { appInfo = packageManager.getApplicationInfo(component.getPackageName(), 0); } catch (NameNotFoundException e) { // if we can't find the package, return 0 padding return padding; } if (appInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Resources r = context.getResources(); padding.left = r.getDimensionPixelSize(com.android.internal.R.dimen.default_app_widget_padding_left); padding.right = r.getDimensionPixelSize(com.android.internal.R.dimen.default_app_widget_padding_right); padding.top = r.getDimensionPixelSize(com.android.internal.R.dimen.default_app_widget_padding_top); padding.bottom = r.getDimensionPixelSize(com.android.internal.R.dimen.default_app_widget_padding_bottom); } return padding; }
private void runApp(List<MainListItem> items) { // 起動中のアプリ情報を取得 Intent it = new Intent(Intent.ACTION_MAIN); it.addCategory(Intent.CATEGORY_LAUNCHER); List<RunningAppProcessInfo> runningApp = activityManager.getRunningAppProcesses(); List<RunningServiceInfo> runningService = activityManager.getRunningServices(100); List<ResolveInfo> appList = packageManager.queryIntentActivities(it, 0); if (runningApp != null) { for (RunningAppProcessInfo app : runningApp) { try { // アプリ名をリストに追加 ApplicationInfo appInfo = packageManager.getApplicationInfo(app.processName, 0); items.add( new MainListItem( packageManager.getApplicationIcon(appInfo), returnLabel(app.processName), app.processName, app.pid, usageMemory(app.pid), 0, true, app.importance, serviceClassNames(runningService, app), mainClassName(appList, app))); } catch (NameNotFoundException e) { e.printStackTrace(); } } } }
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); }
private Drawable getSubtypeIcon( InputMethodInfoCompatWrapper imi, InputMethodSubtypeCompatWrapper subtype) { final PackageManager pm = mService.getPackageManager(); if (imi != null) { final String imiPackageName = imi.getPackageName(); if (DBG) { Log.d( TAG, "Update icons of IME: " + imiPackageName + "," + getSubtypeLocale(subtype) + "," + subtype.getMode()); } if (subtype != null) { return pm.getDrawable( imiPackageName, subtype.getIconResId(), imi.getServiceInfo().applicationInfo); } else if (imi.getSubtypeCount() > 0 && imi.getSubtypeAt(0) != null) { return pm.getDrawable( imiPackageName, imi.getSubtypeAt(0).getIconResId(), imi.getServiceInfo().applicationInfo); } else { try { return pm.getApplicationInfo(imiPackageName, 0).loadIcon(pm); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "IME can't be found: " + imiPackageName); } } } return null; }
public static String getMetaDataValue(Context context, String name) { Object value = null; PackageManager packageManager = context.getPackageManager(); ApplicationInfo applicationInfo; try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 128); if (applicationInfo != null && applicationInfo.metaData != null) { value = applicationInfo.metaData.get(name); } } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Could not read the name in the manifest file.", e); } if (value == null) { throw new RuntimeException( "The name '" + name + "' is not defined in the manifest file's meta data."); } return value.toString(); }
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; }
/** Must not hold the Context. */ public ApplicationInfo( PackageManager pm, ResolveInfo info, IconCache iconCache, HashMap<Object, CharSequence> labelCache) { final String packageName = info.activityInfo.applicationInfo.packageName; this.componentName = new ComponentName(packageName, info.activityInfo.name); this.container = ItemInfo.NO_ID; this.setActivity( componentName, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); try { int appFlags = pm.getApplicationInfo(packageName, 0).flags; if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { flags |= DOWNLOADED_FLAG; if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { flags |= UPDATED_SYSTEM_APP_FLAG; } } firstInstallTime = pm.getPackageInfo(packageName, 0).firstInstallTime; } catch (NameNotFoundException e) { Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName); } iconCache.getTitleAndIcon(this, info, labelCache); }
/** 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); }
/** * 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; }
private static ApplicationInfo getApplicationInfo(Context context) throws PackageManager.NameNotFoundException { PackageManager pm; String packageName; try { pm = context.getPackageManager(); packageName = context.getPackageName(); } catch (RuntimeException e) { /* Ignore those exceptions so that we don't break tests relying on Context like * a android.test.mock.MockContext or a android.content.ContextWrapper with a null * base Context. */ Log.w( TAG, "Failure while trying to obtain ApplicationInfo from Context. " + "Must be running in test mode. Skip patching.", e); return null; } if (pm == null || packageName == null) { // This is most likely a mock context, so just return without patching. return null; } ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); return applicationInfo; }
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) { if (imi != null) { if (DEBUG) { Log.d(TAG, "Update icons of IME: " + imi.getPackageName()); if (subtype != null) { Log.d(TAG, "subtype =" + subtype.getLocale() + "," + subtype.getMode()); } } if (subtype != null) { return mPackageManager.getDrawable( imi.getPackageName(), subtype.getIconResId(), imi.getServiceInfo().applicationInfo); } else if (imi.getSubtypeCount() > 0) { return mPackageManager.getDrawable( imi.getPackageName(), imi.getSubtypeAt(0).getIconResId(), imi.getServiceInfo().applicationInfo); } else { try { return mPackageManager .getApplicationInfo(imi.getPackageName(), 0) .loadIcon(mPackageManager); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "IME can't be found: " + imi.getPackageName()); } } } return null; }
protected String returnLabel(String tag) { try { return (String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(tag, 0)); } catch (NameNotFoundException e) { e.printStackTrace(); return null; } }
private static boolean applicationExists(String packageName) { ApplicationInfo info = null; try { info = pm.getApplicationInfo(packageName, 0); } catch (Exception e) { } return info != null; }
public boolean isAppEnabled(PackageManager pm, String packageName, int flags) { try { ApplicationInfo info = pm.getApplicationInfo(packageName, flags); return info != null && info.enabled; } catch (NameNotFoundException e) { return false; } }
/* * 获取程序的名字 */ public String getAppName(String packname) { try { ApplicationInfo info = pm.getApplicationInfo(packname, 0); return info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
/* * 获取程序 图标 */ public Drawable getAppIcon(String packname) { try { ApplicationInfo info = pm.getApplicationInfo(packname, 0); return info.loadIcon(pm); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
@Implementation public ApplicationInfo getApplicationInfo() { try { final PackageManager packageManager = RuntimeEnvironment.getPackageManager(); return packageManager != null ? packageManager.getApplicationInfo(getPackageName(), 0) : null; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Could not find applicationInfo for current package."); } }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mPackageName = getCallingPackage(); IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE); mService = IMediaProjectionManager.Stub.asInterface(b); if (mPackageName == null) { finish(); return; } PackageManager packageManager = getPackageManager(); ApplicationInfo aInfo; try { aInfo = packageManager.getApplicationInfo(mPackageName, 0); mUid = aInfo.uid; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "unable to look up package name", e); finish(); return; } try { if (mService.hasProjectionPermission(mUid, mPackageName)) { setResult( RESULT_OK, getMediaProjectionIntent(mUid, mPackageName, false /*permanentGrant*/)); finish(); return; } } catch (RemoteException e) { Log.e(TAG, "Error checking projection permissions", e); finish(); return; } String appName = aInfo.loadLabel(packageManager).toString(); mDialog = new AlertDialog.Builder(this) .setIcon(aInfo.loadIcon(packageManager)) .setMessage(getString(R.string.media_projection_dialog_text, appName)) .setPositiveButton(R.string.media_projection_action_text, this) .setNegativeButton(android.R.string.cancel, this) .setView(R.layout.remember_permission_checkbox) .setOnCancelListener(this) .create(); mDialog.create(); ((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this); mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); mDialog.show(); }
/** * Returns the meta data of the specified application * * @param context The android context * @return The meta data bundle */ public static Bundle getMetaData(final Context context) { final PackageManager pm = context.getPackageManager(); final String packageName = context.getPackageName(); try { return pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA).metaData; } catch (NameNotFoundException e) { return null; } }
public static ApplicationInfo getApplicationInfo(Context context) { try { final PackageManager pm = context.getPackageManager(); return pm.getApplicationInfo(context.getPackageName(), 0); } catch (Exception ex) { // this will not happen as the package name is not dynamic but taken from the context Log.e(LOG_TAG, "Failed to determine application info", ex); 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 ""; }
@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; } }
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; }
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); }
/** * 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 ""; } }