我有一个库项目的 .apk 文件,现在我想在我的应用程序项目中使用该 .apk 文件(在 assets 文件夹中),并且在运行我的应用程序项目时,我想将一个 .sql 文件放入该 .apk 文件中我单击一个按钮,然后我想将该 .apk 与该 .sql 文件一起存储在外部 SD 卡中。有可能这样做吗?
问问题
196 次
2 回答
0
我通过使用以下代码得到:
private void onGenButtonClickListener() {
Button generatebutton = (Button) findViewById(R.id.sign_apk);
generatebutton .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
generateAPK();
}
});
}
private void generateAPK() {
try {
String generatedApkPath = GENERATE_APK_TO_DIRECTORY + apkname + ".apk";
String signedApkPath = GENERATE_APK_TO_DIRECTORY + apkname + "-signed.apk";
Log.i("Sign APK", "Going to create signed apk in:" + signedApkPath);
ZipSigner zipSigner = null;
zipSigner = new ZipSigner();
zipSigner.setKeymode("testkey");
zipSigner.signZip(generatedApkPath, signedApkPath);
// After signing apk , delete unsigned apk
new File(generatedApkPath).delete();
Toast.makeText(getApplicationContext(),
"'" + apkname + "-signed.apk' is generated at " + GENERATE_APK_TO_DIRECTORY, Toast.LENGTH_LONG)
.show();
} catch (Throwable t) {
Log.e("Signing apk", "Error while signing apk to external directory", t);
t.printStackTrace();
}
}
于 2013-07-10T13:44:02.903 回答
0
apk is compressed format,so may be you can check how to pack and unpack data from apk.
于 2013-05-14T04:41:45.923 回答