从Android设备上的代码访问APK内容
我需要从设备上运行的同一应用程序的代码访问我的应用程序 APK 的内容。 我编写的这段代码运行良好,并在我的 2.2 和 2.3.3 设备上返回数据。
但是这是合法的方式吗?它适用于从2.1开始到任何未来或现有版本的所有版本吗?
主要原因是检测apk原始签名或重新打包的apk。
这是我访问 META-INF/CERT.RSA 的代码:
String path = this.getApplication().getPackageCodePath();
try
{
ZipFile zfile = new ZipFile(path);
ZipEntry zentry = zfile.getEntry("META-INF/CERT.RSA");
long siz = zentry.getSize();
byte[] buf=new byte[(int) siz];
InputStream istream = zfile.getInputStream(zentry);
int ret = istream.read(buf);
istream.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
提前谢谢您
I need to access contents of my application APK from the code of this same application running on device.
I wrote this code that works perferctly well and return the datа on my 2.2 and 2.3.3 devices.
But Is it a legal way and will it work on all versions starting from 2.1 to any future or existing version?
The main reason is to detect apk original signature or repacked apk.
Here is my code of accessing META-INF/CERT.RSA:
String path = this.getApplication().getPackageCodePath();
try
{
ZipFile zfile = new ZipFile(path);
ZipEntry zentry = zfile.getEntry("META-INF/CERT.RSA");
long siz = zentry.getSize();
byte[] buf=new byte[(int) siz];
InputStream istream = zfile.getInputStream(zentry);
int ret = istream.read(buf);
istream.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这会起作用。
目前它适用于最新的 Android 3.2,并且该方法中没有任何方法被标记为已弃用。
Yes, this will work.
At present it works up to latest Android 3.2, and no method from this approach is marked as deprecated.