WEB开发网
开发学院手机开发Android 开发 android 获取一个apk的信息 阅读

android 获取一个apk的信息

 2010-11-05 00:55:01 来源:WEB开发网   
核心提示:最近在看packageinstaller的ap,对面内容进行总结做一下学习笔记,下面是获取一个apk的application信息的代码:Java代码/** Utility method to get application information for a given packageURI*/public stati

最近在看packageinstaller的ap,对面内容进行总结做一下学习笔记,下面是获取一个apk的application信息的代码:

Java代码

/*

* Utility method to get application information for a given packageURI

*/

public static ApplicationInfo getApplicationInfo(Uri packageURI) {

final String archiveFilePath = packageURI.getPath();

PackageParser packageParser = new PackageParser(archiveFilePath);

File sourceFile = new File(archiveFilePath);

DisplayMetrics metrics = new DisplayMetrics();

metrics.setToDefaults();

PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);

if (pkg == null) {

return null;

}

return pkg.applicationInfo;

}

/*

* Utility method to get application information for a given packageURI

*/

public static ApplicationInfo getApplicationInfo(Uri packageURI) {

final String archiveFilePath = packageURI.getPath();

PackageParser packageParser = new PackageParser(archiveFilePath);

File sourceFile = new File(archiveFilePath);

DisplayMetrics metrics = new DisplayMetrics();

metrics.setToDefaults();

PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);

if (pkg == null) {

return null;

}

return pkg.applicationInfo;

}

这里的Uri的参数是可以是这样形成的:

Creates a Uri from a file. The URI has the form "file://". Encodes path characters with the exception of '/'.

Example: "file:///tmp/android.txt"

Java代码

String fileName="test.apk";

Uri.fromFile(new File(fileName));

Tags:android 获取 一个

编辑录入:coldstar [复制链接] [打 印]
赞助商链接