当前位置: 首页>>代码示例>>Java>>正文


Java PackageManager.getResourcesForApplication方法代码示例

本文整理汇总了Java中android.content.pm.PackageManager.getResourcesForApplication方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getResourcesForApplication方法的具体用法?Java PackageManager.getResourcesForApplication怎么用?Java PackageManager.getResourcesForApplication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.pm.PackageManager的用法示例。


在下文中一共展示了PackageManager.getResourcesForApplication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findSystemApk

import android.content.pm.PackageManager; //导入方法依赖的package包/类
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
    final Intent intent = new Intent(action);
    for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
        if (info.activityInfo != null &&
                (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            final String packageName = info.activityInfo.packageName;
            try {
                final Resources res = pm.getResourcesForApplication(packageName);
                return Pair.create(packageName, res);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:17,代码来源:Utilities.java

示例2: createIconBitmap

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * Returns a bitmap suitable for the all apps view. If the package or the resource do not
 * exist, it returns null.
 */
public static Bitmap createIconBitmap(ShortcutIconResource iconRes, Context context) {
    PackageManager packageManager = context.getPackageManager();
    // the resource
    try {
        Resources resources = packageManager.getResourcesForApplication(iconRes.packageName);
        if (resources != null) {
            final int id = resources.getIdentifier(iconRes.resourceName, null, null);
            return createIconBitmap(resources.getDrawableForDensity(
                    id, LauncherAppState.getIDP(context).fillResIconDpi, context.getTheme()), context);
        }
    } catch (Exception e) {
        // Icon not found.
    }
    return null;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:20,代码来源:LauncherIcons.java

示例3: onReceive

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	if(SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
		
		PendingIntent pendingIntent = null;
		String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
		// We must handle that clean way cause when call just to 
		// get the row in account list expect this to reply correctly
		if(number != null && PhoneCapabilityTester.isPhone(context)) {
			// Build pending intent
			Intent i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.fromParts("tel", number, null));
			pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
		}
		
		// Retrieve and cache infos from the phone app 
		if(!sPhoneAppInfoLoaded) {
   			List<ResolveInfo> callers = PhoneCapabilityTester.resolveActivitiesForPriviledgedCall(context);
   			if(callers != null) {
   				for(final ResolveInfo caller : callers) {
   					if(caller.activityInfo.packageName.startsWith("com.android")) {
   						PackageManager pm = context.getPackageManager();
   						Resources remoteRes;
   						try {
   							// We load the resource in the context of the remote app to have a bitmap to return.
   						    remoteRes = pm.getResourcesForApplication(caller.activityInfo.applicationInfo);
   						    sPhoneAppBmp = BitmapFactory.decodeResource(remoteRes, caller.getIconResource());
   						} catch (NameNotFoundException e) {
   							Log.e(THIS_FILE, "Impossible to load ", e);
   						}
   						break;
   					}
   				}
   			}
   			sPhoneAppInfoLoaded = true;
		}
		
		
		//Build the result for the row (label, icon, pending intent, and excluded phone number)
		Bundle results = getResultExtras(true);
		if(pendingIntent != null) {
			results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
		}
		results.putString(Intent.EXTRA_TITLE, context.getResources().getString(R.string.use_pstn));
		if(sPhoneAppBmp != null) {
			results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
		}
		
		// This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
		results.putString(Intent.EXTRA_PHONE_NUMBER, number);
		
	}
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:54,代码来源:CallHandler.java

示例4: extractWebappInfoFromWebApk

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * Populates {@link WebappInfo} with meta data extracted from WebAPK's Android Manifest.
 * @param webApkPackageName Package name of the WebAPK to extract meta data from.
 * @param url WebAPK start URL.
 * @param source {@link ShortcutSource} that the WebAPK was opened from.
 */
public static WebApkInfo extractWebappInfoFromWebApk(
        String webApkPackageName, String url, int source) {
    WebApkMetaData metaData = extractMetaDataFromWebApk(webApkPackageName);
    if (metaData == null) return null;

    PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager();
    Resources resources;
    try {
        resources = packageManager.getResourcesForApplication(webApkPackageName);
    } catch (PackageManager.NameNotFoundException e) {
        return null;
    }
    Bitmap icon = BitmapFactory.decodeResource(resources, metaData.iconId);
    String encodedIcon = ShortcutHelper.encodeBitmapAsString(icon);

    return WebApkInfo.create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackageName, url,
            metaData.scope, encodedIcon, metaData.name, metaData.shortName,
            metaData.displayMode, metaData.orientation, source, metaData.themeColor,
            metaData.backgroundColor, TextUtils.isEmpty(metaData.iconUrl), webApkPackageName);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:27,代码来源:WebApkMetaDataUtils.java

示例5: getString

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * Get string from given package with given resource name
 *
 * @param context      given context
 * @param packageName  the package name
 * @param resourceName the resource name
 * @return the string that the resource represents
 */
@NonNull
public static String getString(@NonNull final Context context,
                               @NonNull final String packageName,
                               @NonNull final String resourceName) {

    PackageManager pm = context.getPackageManager();

    try {
        //I want to use the clear_activities string in Package com.android.settings
        Resources res = pm.getResourcesForApplication(packageName);
        int resourceId = res.getIdentifier(packageName + ":string/" + resourceName, null, null);
        if (resourceId != 0) {
            return pm.getText(packageName, resourceId, null).toString();
        }
    } catch (Exception ignored) {
    }
    return EMPTY;
}
 
开发者ID:Tenor-Inc,项目名称:tenor-android-core,代码行数:27,代码来源:StringConstant.java

示例6: findSystemApk

import android.content.pm.PackageManager; //导入方法依赖的package包/类
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
    final Intent intent = new Intent(action);
    for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
        if (info.activityInfo != null &&
                (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            final String packageName = info.activityInfo.packageName;
            try {
                final Resources res = pm.getResourcesForApplication(packageName);
                return Pair.create(packageName, res);
            } catch (NameNotFoundException e) {
                Log.w(TAG, "Failed to find resources for " + packageName);
            }
        }
    }
    return null;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:17,代码来源:Utilities.java

示例7: createIconBitmap

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * Returns a bitmap suitable for the all apps view. If the package or the resource do not
 * exist, it returns null.
 */
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;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:22,代码来源:Utilities.java

示例8: get

import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
 * Find and return partner details, or {@code null} if none exists. A partner package is marked
 * by a broadcast receiver declared in the manifest that handles the
 * {@code com.android.setupwizard.action.PARTNER_CUSTOMIZATION} intent action. The overlay
 * package must also be a system package.
 */
public static synchronized Partner get(Context context) {
    if (!sSearched) {
        PackageManager pm = context.getPackageManager();
        final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION);
        for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
            if (info.activityInfo == null) {
                continue;
            }
            final ApplicationInfo appInfo = info.activityInfo.applicationInfo;
            if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                try {
                    final Resources res = pm.getResourcesForApplication(appInfo);
                    sPartner = new Partner(appInfo.packageName, res);
                    break;
                } catch (NameNotFoundException e) {
                    Log.w(TAG, "Failed to find resources for " + appInfo.packageName);
                }
            }
        }
        sSearched = true;
    }
    return sPartner;
}
 
开发者ID:Trumeet,项目名称:SetupWizardLibCompat,代码行数:30,代码来源:Partner.java

示例9: getResources

import android.content.pm.PackageManager; //导入方法依赖的package包/类
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);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:Utils.java

示例10: getResources

import android.content.pm.PackageManager; //导入方法依赖的package包/类
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;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:12,代码来源:PluginManager.java

示例11: getResources

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public Resources getResources() {
    Resources rs =  super.getResources();
    if (rs == null){
        PackageManager pm = getPackageManager();
        try {
            rs = pm.getResourcesForApplication(getApplicationInfo());
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
    return rs;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:15,代码来源:AtlasBridgeApplication.java

示例12: get

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Nullable
@ColorInt
public static Integer get(Context context, ComponentName componentName) {
    PackageManager packageManager = context.getPackageManager();

    ActivityInfo activityInfo = null;
    PackageInfo packageInfo = null;
    Resources resources = null, activityResources = null;
    try {
        packageInfo = packageManager.getPackageInfo(componentName.getPackageName(), PackageManager.GET_META_DATA);
        resources = packageManager.getResourcesForApplication(packageInfo.applicationInfo);
        activityInfo = packageManager.getActivityInfo(componentName, 0);
        activityResources = packageManager.getResourcesForActivity(componentName);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    if (packageInfo != null && resources != null) {
        if (activityInfo != null && activityResources != null) {
            List<Integer> activityStatusBarColors = getResourceColors(activityInfo.packageName, resources, activityInfo.theme);
            if (activityStatusBarColors.size() > 0) {
                return activityStatusBarColors.get(0);
            }
        }

        List<Integer> statusBarColors = getResourceColors(packageInfo.packageName, resources, packageInfo.applicationInfo.theme);
        if (statusBarColors.size() > 0) {
            return statusBarColors.get(0);
        }

        if (packageInfo.activities != null) {
            for (ActivityInfo otherActivityInfo : packageInfo.activities) {
                List<Integer> otherStatusBarColors = getResourceColors(packageInfo.packageName, resources, otherActivityInfo.theme);
                if (otherStatusBarColors.size() > 0) {
                    return otherStatusBarColors.get(0);
                }
            }
        }
    }

    return null;
}
 
开发者ID:TheAndroidMaster,项目名称:PaletteGetter,代码行数:42,代码来源:PaletteGetter.java

示例13: getHKDictionaries

import android.content.pm.PackageManager; //导入方法依赖的package包/类
static void getHKDictionaries(PackageManager packageManager) {
    Intent dictIntent = new Intent(HK_INTENT_DICT);
    List<ResolveInfo> dictPacks = packageManager.queryIntentActivities(dictIntent, 0);
    for (ResolveInfo ri : dictPacks) {
        ApplicationInfo appInfo = ri.activityInfo.applicationInfo;
        String pkgName = appInfo.packageName;
        boolean success = false;
        try {
            Resources res = packageManager.getResourcesForApplication(appInfo);
            Log.i("KP2AK", "Found dictionary plugin package: " + pkgName);
            int langId = res.getIdentifier("dict_language", "string", pkgName);
            if (langId == 0) continue;
            String lang = res.getString(langId);
            int[] rawIds = null;
            
            // Try single-file version first
            int rawId = res.getIdentifier("main", "raw", pkgName);
            if (rawId != 0) {
                rawIds = new int[] { rawId };
            } else {
                // try multi-part version
                int parts = 0;
                List<Integer> ids = new ArrayList<Integer>();
                while (true) {
                    int id = res.getIdentifier("main" + parts, "raw", pkgName);
                    if (id == 0) break;
                    ids.add(id);
                    ++parts;
                }
                if (parts == 0) continue; // no parts found
                rawIds = new int[parts];
                for (int i = 0; i < parts; ++i) rawIds[i] = ids.get(i);
            }
            DictPluginSpec spec = new DictPluginSpecHK(pkgName, rawIds);
            mPluginDicts.put(lang, spec);
            Log.i("KP2AK", "Found plugin dictionary: lang=" + lang + ", pkg=" + pkgName);
            success = true;
        } catch (NameNotFoundException e) {
            Log.i("KP2AK", "bad");
        } finally {
            if (!success) {
                Log.i("KP2AK", "failed to load plugin dictionary spec from " + pkgName);
            }
        }
    }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:47,代码来源:PluginManager.java

示例14: getAppLabelEn

import android.content.pm.PackageManager; //导入方法依赖的package包/类
@TargetApi(17)
public static String getAppLabelEn(Context context, String pkgName, String def) {
    if (context == null || TextUtils.isEmpty(pkgName)) {
        return def;
    }

    String result = def;
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo applicationInfo = packageManager.getPackageInfo(pkgName, 0).applicationInfo;

        Configuration configuration = new Configuration();
        // It's better, I think, to use Locale.ENGLISH
        // instead of Locale.ROOT (although I want to do).
        if (C.SDK >= 17) {
            configuration.setLocale(Locale.ENGLISH);
        } else {
            configuration.locale = Locale.ENGLISH;
        }
        // The result is a value in disorder maybe if using:
        //     packageManager.getResourcesForApplication(PACKAGE_NAME)
        Resources resources = packageManager.getResourcesForApplication(applicationInfo);
        resources.updateConfiguration(configuration,
                context.getResources().getDisplayMetrics());
        int labelResId = applicationInfo.labelRes;
        if (labelResId != 0) {
            // If the localized label is not added, the default is returned.
            // NOTICE!!!If the default were empty, Resources$NotFoundException would be called.
            result = resources.getString(labelResId);
        }

        /*
         * NOTICE!!!
         * We have to restore the locale.
         * On the one hand,
         * it will influence the label of Activity, etc..
         * On the other hand,
         * the got "resources" equals the one "this.getResources()" if the current .apk file
         * happens to be this APK Checker(com.by_syk.apkchecker).
         * We need to restore the locale, or the language of APK Checker will change to English.
         */
        if (C.SDK >= 17) {
            configuration.setLocale(Locale.getDefault());
        } else {
            configuration.locale = Locale.getDefault();
        }
        resources.updateConfiguration(configuration, context.getResources().getDisplayMetrics());
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}
 
开发者ID:homeii,项目名称:GxIconDIY,代码行数:54,代码来源:PkgUtil.java

示例15: setIcons

import android.content.pm.PackageManager; //导入方法依赖的package包/类
public void setIcons() {
	iconsData = new HashMap<String, String>();
	iconBacks = null;
	iconMask = null;
	iconUpon = null;
	factor = 1.0f;
	iconPackRes = null;
	if (iconPackName.equals("default")) {
		return;
	}
	transformDrawable = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Keys.TRANSFORM_DRAWABLE, true);
	String component = null;
	String drawable = null;
	PackageManager pm = context.getPackageManager();
	iconBacks = new ArrayList<Bitmap>();
	try {
		iconPackRes = pm.getResourcesForApplication(iconPackName);
	} catch (PackageManager.NameNotFoundException nameNotFound) {
	
	}
	try {
		int id = iconPackRes.getIdentifier("appfilter", "xml", iconPackName);
		XmlPullParser parser = iconPackRes.getXml(id);
		int parserEvent = parser.getEventType();
		
		while (parserEvent != XmlPullParser.END_DOCUMENT) {
			if (parserEvent == XmlPullParser.START_TAG){
				if (parser.getName().equals("item")) {
					for (int i = 0; i < parser.getAttributeCount(); i++) {
						if (parser.getAttributeName(i).equals("component")) {
							component = parser.getAttributeValue(i);
							int c = component.indexOf("{");
							component = component.substring(c+1, component.length()-1);
						} else if (parser.getAttributeName(i).equals("drawable")) {
							drawable = parser.getAttributeValue(i);
						}
					}
					iconsData.put(component, drawable);
				} else if (parser.getName().equals("iconback")) {
					for (int i = 0; i < parser.getAttributeCount(); i++) {
						iconBacks.add(loadBitmap(parser.getAttributeValue(i)));
					}
				} else if (parser.getName().equals("iconmask")) {
					if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals("iconmask")) {
						iconMask = loadBitmap(parser.getAttributeValue(0));
					}
				} else if (parser.getName().equals("iconupon")) {
					if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals("iconupon")) {
						iconUpon = loadBitmap(parser.getAttributeValue(0));
					}
				} else if (parser.getName().equals("scale")) {
					if (parser.getAttributeCount() > 0 && parser.getAttributeName(0).equals("factor")) {
						factor = Float.valueOf(parser.getAttributeValue(0));
					}
				}
			}
			parserEvent = parser.next();
		}
		
	} catch (Exception e) {
		//iconsData.put("error", e.toString());
	}
}
 
开发者ID:HenriDellal,项目名称:emerald,代码行数:64,代码来源:IconPackManager.java


注:本文中的android.content.pm.PackageManager.getResourcesForApplication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。