@Override public Resources getResourcesForApplication(ApplicationInfo app) throws NameNotFoundException { return mBase.getResourcesForApplication(app); }
@Override public Resources getResourcesForApplication(String appPackageName) throws NameNotFoundException { return mBase.getResourcesForApplication(appPackageName); }
static Resources getResources(Context context, Request data) throws FileNotFoundException { if (data.resourceId != 0 || data.uri == null) { return context.getResources(); } String pkg = data.uri.getAuthority(); if (pkg == null) throw new FileNotFoundException("No package provided: " + data.uri); try { PackageManager pm = context.getPackageManager(); return pm.getResourcesForApplication(pkg); } catch (PackageManager.NameNotFoundException e) { throw new FileNotFoundException("Unable to obtain resources for package: " + data.uri); } }
static Context mockPackageResourceContext() { Context context = mock(Context.class); PackageManager pm = mock(PackageManager.class); Resources res = mock(Resources.class); doReturn(pm).when(context).getPackageManager(); try { doReturn(res).when(pm).getResourcesForApplication(RESOURCE_PACKAGE); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } doReturn(RESOURCE_ID_1).when(res).getIdentifier(RESOURCE_NAME, RESOURCE_TYPE, RESOURCE_PACKAGE); return context; }
} else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName);
} else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName);
Drawable loadIconForResolveInfo(ResolveInfo ri) { Drawable dr; try { if (ri.resolvePackageName != null && ri.icon != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); if (dr != null) { return dr; } } final int iconRes = ri.getIconResource(); if (iconRes != 0) { dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); if (dr != null) { return dr; } } } catch (PackageManager.NameNotFoundException e) { VLog.e(TAG, "Couldn't find resources for package\n" + VLog.getStackTraceString(e)); } return ri.loadIcon(mPm); }
@Test public void getResourcesForApplication_currentApplication() throws Exception { assertThat( packageManager .getResourcesForApplication("org.robolectric") .getString(R.string.app_name)) .isEqualTo(ApplicationProvider.getApplicationContext().getString(R.string.app_name)); }
} else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName);
@Test public void getResourcesForApplication_unknownPackage() { try { packageManager.getResourcesForApplication("non.existent.package"); fail("should have thrown NameNotFoundException"); } catch (NameNotFoundException e) { // expected } }
/** Gets the resources of another installed application */ private static Resources getExternalResources(Context ctx, String namespace) { PackageManager pm = ctx.getPackageManager(); try { return (pm == null) ? null : pm.getResourcesForApplication(namespace); } catch (PackageManager.NameNotFoundException ex) { return null; } } /** Gets a resource ID from another installed application */ private static int getExternalIdentifier(Context ctx, String namespace, String key, String type) { Resources res = getExternalResources(ctx, namespace); return (res == null) ? 0 : res.getIdentifier(key, type, namespace); } /** Gets a String resource from another installed application */ public static String getExternalString(Context ctx, String namespace, String key, String defVal) { int resId = getExternalIdentifier(ctx, namespace, key, "string"); if (resId != 0) { Resources res = getExternalResources(ctx, namespace); return res.getString(resId); } else { return defVal; } }
@Test public void getResourcesForApplication_anotherPackage() throws Exception { PackageInfo packageInfo = new PackageInfo(); packageInfo.packageName = "another.package"; ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.packageName = "another.package"; packageInfo.applicationInfo = applicationInfo; shadowPackageManager.installPackage(packageInfo); assertThat(packageManager.getResourcesForApplication("another.package")).isNotNull(); assertThat(packageManager.getResourcesForApplication("another.package")) .isNotEqualTo(ApplicationProvider.getApplicationContext().getResources()); }
@Override public Resources getResourcesForApplication(String appPackageName) throws NameNotFoundException { return mBase.getResourcesForApplication(appPackageName); }
@Override public Resources getResourcesForApplication(ApplicationInfo app) throws NameNotFoundException { return mBase.getResourcesForApplication(app); }
final String packName = "com.example2.app"; String mDrawableName = "app_icon"; try { PackageManager manager = getPackageManager(); Resources mApk1Resources = manager.getResourcesForApplication(packName); int mDrawableResID = mApk1Resources.getIdentifier(mDrawableName, "drawable",packName); Drawable myDrawable = mApk1Resources.getDrawable( mDrawableResID ); if( myDrawable != null ) TEST.setBackgroundDrawable(myDrawable ); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
private Resources getPackageResources() { final PackageManager packageManager = pinpointContext.getApplicationContext().getPackageManager(); try { final String packageName = pinpointContext.getApplicationContext().getPackageName(); final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA); return packageManager.getResourcesForApplication(applicationInfo); } catch (final PackageManager.NameNotFoundException ex) { log.error("Can't find resources for our application package.", ex); return null; } }
private Bitmap getFullResIcon(ApplicationInfo info) { try { Resources resources = pm.getResourcesForApplication(info.packageName); if (resources != null) { int iconId = info.icon; if (iconId != 0) { return getFullResIcon(resources, iconId); } } } catch (PackageManager.NameNotFoundException ignored) { } return getFullResDefaultActivityIcon(); }
private int getNotificationIconResourceId( final String drawableResourceName) { final PackageManager packageManager = pinpointContext.getApplicationContext().getPackageManager(); try { 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; } }
iconPackres = pm.getResourcesForApplication(iconsPackPackageName); int appfilterid = iconPackres.getIdentifier("appfilter", "xml", iconsPackPackageName); if (appfilterid > 0) {
Resources getResources(Context context) { PackageManager packageManager = context.getPackageManager(); Resources res = null; try { ApplicationInfo appInfo = packageManager.getApplicationInfo(mPackageName, 0); res = packageManager.getResourcesForApplication(appInfo); } catch (NameNotFoundException e) { Log.i(TAG, "couldn't get resources"); } return res; }