List of usage examples for android.content.pm PackageManager getResourcesForApplication
public abstract Resources getResourcesForApplication(String appPackageName) throws NameNotFoundException;
From source file:im.vector.VectorApp.java
/** * Provides the device locale// ww w .j a va 2 s . com * * @return the device locale */ public static Locale getDeviceLocale() { Context context = VectorApp.getInstance(); Locale locale = getApplicationLocale(); try { PackageManager packageManager = context.getPackageManager(); Resources resources = packageManager.getResourcesForApplication("android"); locale = resources.getConfiguration().locale; } catch (Exception e) { Log.e(LOG_TAG, "## getDeviceLocale() failed " + e.getMessage()); } return locale; }
From source file:me.piebridge.prevent.framework.SystemReceiver.java
private void showUpdated(String packageName, int size) { try {// w w w . j av a 2 s. c o m PackageManager pm = mContext.getPackageManager(); Resources resources = pm.getResourcesForApplication(BuildConfig.APPLICATION_ID); String message = resources.getString(R.string.updated_prevents, size) + "(" + getLabel(pm, packageName) + ")"; Toast.makeText(mContext, message, Toast.LENGTH_LONG).show(); } catch (PackageManager.NameNotFoundException e) { PreventLog.d("cannot find application " + BuildConfig.APPLICATION_ID, e); } catch (RuntimeException e) { PreventLog.d("cannot show toast", e); } }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private CharSequence getLabel(PackageManager pm, ApplicationInfo info) throws PackageManager.NameNotFoundException { CharSequence label = null;//from w w w . jav a2 s.c o m if ("com.android.vending".equals(info.packageName)) { Resources resources = pm.getResourcesForApplication(info); int appName = resources.getIdentifier("app_name", "string", info.packageName); if (appName > 0) { label = resources.getText(appName); } } if (TextUtils.isEmpty(label)) { label = pm.getApplicationLabel(info); } return label; }
From source file:com.android.contacts.common.model.ContactLoader.java
private void loadDirectoryMetaData(Contact result) { long directoryId = result.getDirectoryId(); Cursor cursor = getContext().getContentResolver().query( ContentUris.withAppendedId(Directory.CONTENT_URI, directoryId), DirectoryQuery.COLUMNS, null, null, null);/*from w w w. j ava 2 s. c o m*/ if (cursor == null) { return; } try { if (cursor.moveToFirst()) { final String displayName = cursor.getString(DirectoryQuery.DISPLAY_NAME); final String packageName = cursor.getString(DirectoryQuery.PACKAGE_NAME); final int typeResourceId = cursor.getInt(DirectoryQuery.TYPE_RESOURCE_ID); final String accountType = cursor.getString(DirectoryQuery.ACCOUNT_TYPE); final String accountName = cursor.getString(DirectoryQuery.ACCOUNT_NAME); final int exportSupport = cursor.getInt(DirectoryQuery.EXPORT_SUPPORT); String directoryType = null; if (!TextUtils.isEmpty(packageName)) { PackageManager pm = getContext().getPackageManager(); try { Resources resources = pm.getResourcesForApplication(packageName); directoryType = resources.getString(typeResourceId); } catch (NameNotFoundException e) { Log.w(TAG, "Contact directory resource not found: " + packageName + "." + typeResourceId); } } result.setDirectoryMetaData(displayName, directoryType, accountType, accountName, exportSupport); } } finally { cursor.close(); } }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private int getNotificationIconResourceId(final String drawableResourceName) { final PackageManager packageManager = pinpointContext.getApplicationContext().getPackageManager(); try {//from w w w . j av a 2s. c o m final String packageName = pinpointContext.getApplicationContext().getPackageName(); final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA); final Resources resources = packageManager.getResourcesForApplication(applicationInfo); if (drawableResourceName != null) { final int resId = resources.getIdentifier(drawableResourceName, "drawable", packageName); if (resId != INVALID_RESOURCE) { return resId; } } return applicationInfo.icon; } catch (final PackageManager.NameNotFoundException ex) { log.error("Can't find icon for our application package.", ex); // 0 is an invalid resource id, so use it to indicate failure to // retrieve the resource. return INVALID_RESOURCE; } }
From source file:com.github.shareme.gwschips.library.BaseRecipientAdapter.java
public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor, Account account) {/* ww w. ja va 2 s . co m*/ final PackageManager packageManager = context.getPackageManager(); final List<DirectorySearchParams> paramsList = new ArrayList<>(); DirectorySearchParams preferredDirectory = null; while (directoryCursor.moveToNext()) { final long id = directoryCursor.getLong(DirectoryListQuery.ID); // Skip the local invisible directory, because the default directory already includes // all local results. if (id == Directory.LOCAL_INVISIBLE) { continue; } final DirectorySearchParams params = new DirectorySearchParams(); final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME); final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID); params.directoryId = id; params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME); params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME); params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE); if (packageName != null && resourceId != 0) { try { final Resources resources = packageManager.getResourcesForApplication(packageName); params.directoryType = resources.getString(resourceId); } catch (NameNotFoundException e) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e); } } // If an account has been provided and we found a directory that // corresponds to that account, place that directory second, directly // underneath the local contacts. if (account != null && account.name.equals(params.accountName) && account.type.equals(params.accountType)) { preferredDirectory = params; } else { paramsList.add(params); } } if (preferredDirectory != null) { paramsList.add(1, preferredDirectory); } return paramsList; }
From source file:com.android.ex.chips.BaseRecipientAdapter.java
public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor, Account account) {//from w w w.j a v a 2s .c o m final PackageManager packageManager = context.getPackageManager(); final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>(); DirectorySearchParams preferredDirectory = null; while (directoryCursor.moveToNext()) { final long id = directoryCursor.getLong(DirectoryListQuery.ID); // Skip the local invisible directory, because the default directory already includes // all local results. if (id == Directory.LOCAL_INVISIBLE) { continue; } final DirectorySearchParams params = new DirectorySearchParams(); final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME); final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID); params.directoryId = id; params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME); params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME); params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE); if (packageName != null && resourceId != 0) { try { final Resources resources = packageManager.getResourcesForApplication(packageName); params.directoryType = resources.getString(resourceId); if (params.directoryType == null) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName); } } catch (NameNotFoundException e) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e); } } // If an account has been provided and we found a directory that // corresponds to that account, place that directory second, directly // underneath the local contacts. if (account != null && account.name.equals(params.accountName) && account.type.equals(params.accountType)) { preferredDirectory = params; } else { paramsList.add(params); } } if (preferredDirectory != null) { paramsList.add(1, preferredDirectory); } return paramsList; }
From source file:cm.confide.ex.chips.BaseRecipientAdapter.java
public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor, Account account) {// w w w. j a v a2 s . co m final PackageManager packageManager = context.getPackageManager(); final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>(); DirectorySearchParams preferredDirectory = null; while (directoryCursor.moveToNext()) { final long id = directoryCursor.getLong(DirectoryListQuery.ID); // Skip the local invisible directory, because the default directory already includes // all local results. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (id == Directory.LOCAL_INVISIBLE) { continue; } } final DirectorySearchParams params = new DirectorySearchParams(); final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME); final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID); params.directoryId = id; params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME); params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME); params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE); if (packageName != null && resourceId != 0) { try { final Resources resources = packageManager.getResourcesForApplication(packageName); params.directoryType = resources.getString(resourceId); if (params.directoryType == null) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName); } } catch (NameNotFoundException e) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e); } } // If an account has been provided and we found a directory that // corresponds to that account, place that directory second, directly // underneath the local contacts. if (account != null && account.name.equals(params.accountName) && account.type.equals(params.accountType)) { preferredDirectory = params; } else { paramsList.add(params); } } if (preferredDirectory != null) { paramsList.add(1, preferredDirectory); } return paramsList; }
From source file:com.android.launcher3.Utilities.java
/** * Returns a bitmap suitable for the all apps view. If the package or the resource do not * exist, it returns null./*from w ww . ja va2 s. c o m*/ */ public static Bitmap createIconBitmap(String packageName, String resourceName, Context context) { PackageManager packageManager = context.getPackageManager(); // the resource try { Resources resources = packageManager.getResourcesForApplication(packageName); if (resources != null) { final int id = resources.getIdentifier(resourceName, null, null); return createIconBitmap( resources.getDrawableForDensity(id, LauncherAppState.getInstance().getInvariantDeviceProfile().fillResIconDpi), context); } } catch (Exception e) { // Icon not found. } return null; }
From source file:com.android.mtkex.chips.BaseRecipientAdapter.java
public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor, Account account) {/* w w w. ja v a2 s. c o m*/ Log.d(TAG, "[setupOtherDirectories]"); /// M: MTK debug log final PackageManager packageManager = context.getPackageManager(); final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>(); DirectorySearchParams preferredDirectory = null; while (directoryCursor.moveToNext()) { final long id = directoryCursor.getLong(DirectoryListQuery.ID); // Skip the local invisible directory, because the default directory already includes // all local results. if (id == Directory.LOCAL_INVISIBLE) { continue; } final DirectorySearchParams params = new DirectorySearchParams(); final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME); final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID); params.directoryId = id; params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME); params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME); params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE); if (packageName != null && resourceId != 0) { try { final Resources resources = packageManager.getResourcesForApplication(packageName); params.directoryType = resources.getString(resourceId); if (params.directoryType == null) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName); } } catch (NameNotFoundException e) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e); } } // If an account has been provided and we found a directory that // corresponds to that account, place that directory second, directly // underneath the local contacts. /// M: Add a condition to make sure no directories would be missed for account with multiple directories if (preferredDirectory == null && account != null && account.name.equals(params.accountName) && account.type.equals(params.accountType)) { preferredDirectory = params; } else { paramsList.add(params); } } if (preferredDirectory != null) { paramsList.add(1, preferredDirectory); } return paramsList; }