反射获取包名的方法:
/**
* <br>功能简述:采用反射获取包名
* <br>功能详细描述:
* <br>注意:
* @param ctx
* @param apkPath
* @return
*/
private static HashMap<String, String> sApkPathMap;
public static String getApkFileInfoFromReflect(Context ctx, String apkPath) {
File apkFile = new File(apkPath);
if (!apkFile.exists() || !apkPath.toLowerCase().endsWith(".apk")) {
return null;
}
if (sApkPathMap != null) {
synchronized (sApkPathMap) {
Iterator iter = sApkPathMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
if (val != null && ((String) val).equals(apkPath)) {
return (String) key;
}
}
}
}
String PATH_PackageParser =