android ApplicationInfo类

1)获取apk文件的图标

	public static Drawable getApkFileIcon(String apkPath, Context context) {
		PackageManager pm = context.getPackageManager();
		PackageInfo info = pm.getPackageArchiveInfo(apkPath,
				PackageManager.GET_ACTIVITIES);
		if (info != null) {
			ApplicationInfo appInfo = info.applicationInfo;
			if (appInfo != null) {
				try {
					appInfo.publicSourceDir = apkPath;
					return pm.getApplicationIcon(appInfo);
				} catch (OutOfMemoryError e) {
				}
			}
		}
		return null;

	}


 

2)获取AndroidManifest.xml中<meta-data>标签中定义的值

        PackageManager manager = this.getPackageManager();

        try {
            // 设置PackageManager.GET_META_DATA标识位是必须的
            PackageInfo info = manager.getPackageInfo(this.getPackageName(),
                    PackageManager.GET_CONFIGURATIONS | PackageManager.GET_META_DATA);
            Object myChannel = info.applicationInfo.metaData.get("meta-data-key");

            if ((myChannel != null) && (myChannel instanceof Integer)) {
                // do something
            }

        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }


 

你可能感兴趣的:(android,String,null)