android.content.Context.getPackageCodePath()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(465)

本文整理了Java中android.content.Context.getPackageCodePath()方法的一些代码示例,展示了Context.getPackageCodePath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getPackageCodePath()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getPackageCodePath

Context.getPackageCodePath介绍

暂无

代码示例

代码示例来源:origin: oasisfeng/condom

@Override public String getPackageCodePath() {
  return mBase.getPackageCodePath();
}

代码示例来源:origin: joyoyao/superCleanMaster

String packageCodePath = context.getPackageCodePath();
Process process = null;
DataOutputStream os = null;

代码示例来源:origin: Trumeet/MiPushFramework

@Override public String getPackageCodePath() {
  return mBase.getPackageCodePath();
}

代码示例来源:origin: com.uphyca/android-junit4

@TargetApi(8)
private String getContextPackageCodePath() {
  //getPackageCodePath() was hidden 
  return getContext().getPackageCodePath();
}

代码示例来源:origin: com.uphyca/android-junit4

@TargetApi(8)
private String getTargetContextPackageCodePath() {
  //getPackageCodePath() was hidden 
  return getTargetContext().getPackageCodePath();
}

代码示例来源:origin: esmasui/AndroidJUnit4

@TargetApi(8)
private String getTargetContextPackageCodePath() {
  //getPackageCodePath() was hidden 
  return getTargetContext().getPackageCodePath();
}

代码示例来源:origin: esmasui/AndroidJUnit4

@TargetApi(8)
private String getContextPackageCodePath() {
  //getPackageCodePath() was hidden 
  return getContext().getPackageCodePath();
}

代码示例来源:origin: stackoverflow.com

private static long getApkFileChecksum(Context context) {
   String apkPath = context.getPackageCodePath();
   Long chksum = null;
   try {
     // Open the file and build a CRC32 checksum.
     FileInputStream fis = new FileInputStream(new File(apkPath));
     CRC32 chk = new CRC32();
     CheckedInputStream cis = new CheckedInputStream(fis, chk);
     byte[] buff = new byte[80];
     while (cis.read(buff) >= 0) ;
     chksum = chk.getValue();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return chksum;
 }

代码示例来源:origin: w568w/fuckView

/**
 * 根据包名构建目标Context,并调用getPackageCodePath()来定位apk
 *
 * @param context           context参数
 * @param modulePackageName 当前模块包名
 * @return return apk file
 */
private File findApkFile(Context context, String modulePackageName) {
  if (context == null) {
    return null;
  }
  try {
    Context moudleContext = context.createPackageContext(modulePackageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
    String apkPath = moudleContext.getPackageCodePath();
    return new File(apkPath);
  } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: Yaerin/XposedHider

/**
 * 根据包名构建目标Context,并调用getPackageCodePath()来定位apk
 *
 * @param context           context参数
 * @param modulePackageName 当前模块包名
 * @return return apk file
 */
private File findApkFile(Context context, String modulePackageName) {
  if (context == null) {
    return null;
  }
  try {
    Context moduleContext = context.createPackageContext(
        modulePackageName,
        Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
    String apkPath = moduleContext.getPackageCodePath();
    return new File(apkPath);
  } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: stackoverflow.com

public static String getApkFileDigest(Context context) {
   String apkPath = context.getPackageCodePath();
   try {
     byte[] hashed= getDigest(new FileInputStream(apkPath), "SHA-256");
     return Base64.encodeToString(hashed, Base64.DEFAULT);
   } catch (Throwable throwable) {
     throwable.printStackTrace();
   }
   return null;
 }
 public static final int BUFFER_SIZE = 2048;
 public static byte[] getDigest(InputStream in, String algorithm) throws Throwable {
   MessageDigest md = MessageDigest.getInstance(algorithm);
   try {
     DigestInputStream dis = new DigestInputStream(in, md);
     byte[] buffer = new byte[BUFFER_SIZE];
     while (dis.read(buffer) != -1) {
     }
     dis.close();
   } finally {
     in.close();
   }
   return md.digest();
 }

代码示例来源:origin: z-android/ZLayer

String packageCodePath = context.getPackageCodePath();
Process process = null;
DataOutputStream os = null;

代码示例来源:origin: Unity-Technologies/unity-ads-android

public static String getApkDigest() throws Exception {
  String apkDigest = null;
  String apkPath = ClientProperties.getApplicationContext().getPackageCodePath();
  InputStream inputStream = null;
  try {
    inputStream = new FileInputStream(new File(apkPath));
    apkDigest = Utilities.Sha256(inputStream);
  }
  finally {
    try {
      if (inputStream != null) {
        inputStream.close();
      }
    } catch (IOException e) {
    }
  }
  return apkDigest;
}

代码示例来源:origin: Odoo-mobile/framework

public void makeReady(Context context) {
  try {
    DexFile dexFile = new DexFile(context.getPackageCodePath());
    for (Enumeration<String> item = dexFile.entries(); item.hasMoreElements(); ) {
      String element = item.nextElement();
      if (element.startsWith(App.class.getPackage().getName())) {
        Class<? extends OModel> clsName = (Class<? extends OModel>) Class.forName(element);
        if (clsName != null && clsName.getSuperclass() != null &&
            OModel.class.isAssignableFrom(clsName.getSuperclass())) {
          String modelName = getModelName(context, clsName);
          if (modelName != null) {
            this.models.put(modelName, clsName);
          }
        }
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: denzilferreira/aware-client

/**
 * Given a package and class name, check if the class exists or not.
 *
 * @param package_name
 * @param class_name
 * @return true if exists, false otherwise
 */
public static boolean isClassAvailable(Context context, String package_name, String class_name) {
  if (context.getResources().getBoolean(R.bool.standalone)) {
    try {
      Class.forName(package_name + "." + class_name);
      return true;
    } catch (ClassNotFoundException e) {
      return false;
    }
  } else {
    try {
      Context package_context = context.createPackageContext(package_name, Context.CONTEXT_IGNORE_SECURITY + Context.CONTEXT_INCLUDE_CODE);
      DexFile df = new DexFile(package_context.getPackageCodePath());
      for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) {
        String className = iter.nextElement();
        if (className.contains(class_name)) return true;
      }
      return false;
    } catch (IOException | NameNotFoundException e) {
      return false;
    }
  }
}

代码示例来源:origin: gdpancheng/LoonAndroid3

/**
   * @param context
   * @param basepath
   * @param callback
   * @param filter
   */
  public static void doScannerFilter(Context context, String basepath, CallbackTemplate<String> callback, FilterTemplate<String> filter) {
    try {
      DexFile dexFile = new DexFile(context.getPackageCodePath());
      Enumeration<String> it = dexFile.entries();
      while (it.hasMoreElements()) {
        String classname = it.nextElement();
        if (classname.startsWith(basepath) && (filter == null || filter.doWith(classname))) {
          callback.doWith(classname);
        }
      }
    } catch (BreakException e) {
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: gdpancheng/LoonAndroid3

/**
 * 对虚拟机中的类名进行过滤
 * 
 * @author gdpancheng@gmail.com 2013-9-20 下午11:41:05
 * @param context
 * @param callback
 * @param filter
 * @return void
 */
public static void doScannerFilter(Context context, CallbackBreak<String> callback, FilterTemplate<String> filter) {
  try {
    // cont.getPackageCodePath() 获取自身APK的路径
    DexFile dexFile = new DexFile(context.getPackageCodePath());
    // Enumeration<String> entries ()迭代其中的类名
    Enumeration<String> it = dexFile.entries();
    while (it.hasMoreElements()) {
      String classname = it.nextElement();
      if (filter == null || filter.doWith(classname)) {
        callback.doWith(classname);
      }
      classname = null;
    }
    if (dexFile != null) {
      dexFile.close();
    }
    dexFile = null;
  } catch (BreakException e) {
  } catch (IOException e) {
  }
}

代码示例来源:origin: lypeer/GoogleClock

Log.e(mContext.getPackageCodePath(), "ResId is wrong .");
return;

代码示例来源:origin: iReaderAndroid/ZeusPlugin

nativeLibraryDir = applicationInfo.nativeLibraryDir;
classLoader = new ZeusClassLoader(mBaseContext.getPackageCodePath(), mBaseContext.getClassLoader(), nativeLibraryDir);

代码示例来源:origin: iReaderAndroid/ZeusPlugin

nativeLibraryDir = applicationInfo.nativeLibraryDir;
ZeusClassLoader classLoader = new ZeusClassLoader(mBaseContext.getPackageCodePath(), cl, nativeLibraryDir);
classLoader.addAPKPath(pluginId, pluginApkPath, PluginUtil.getLibFileInside(pluginId));
PluginUtil.setField(mPackageInfo, "mClassLoader", classLoader);

相关文章

微信公众号

最新文章

更多

Context类方法