android 读取其它应用的资源

/**
  * 获得应用包下面,asset中version中的文件内容
  * 一、int logResId = context.getResources().getIdentifier("log", "string", packageName);这种方式是获取不到id的
  * 二、通过反射的方式  clazz = packageContext.getClassLoader().loadClass(className); 也是获取不到id的
  *
  * @param packageName @return
  */
 public String getVersionText(String packageName) {
     try {
         Context packageContext = context.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
         InputStream is = packageContext.getResources().getAssets().open("version.txt");
         return readInputStream(is);
     } catch (PackageManager.NameNotFoundException e) {
         e.printStackTrace();
     } catch (IOException e) {
         e.printStackTrace();
     }
     return "";
 }

你可能感兴趣的:(android 读取其它应用的资源)