「そんな事する奴おらんやろ~」的な話で申し訳ないのですが、
Android アプリのプログラム内から自身の apk ファイルを展開し、再度、(SDカードへ)圧縮してみました。
結果は見事に成功で、ちゃんとインストールできて動作します(当り前か・・・)。
※ファイルサイズが微妙に違うのは、zipalign の差?
※展開中は、1ファイル(=エントリ)毎の識別ができますので、○○だったらゴニョゴニョみたいなこともできます
※もちろん、書き換えたら署名が必要なので、その辺は自前でやるしかなさそうです^^;
ソースコード
// /data/app/com.adakoda.android.ziptest.apk
String inPath = getPackageCodePath();
// /sdcard/ZipTest.apk
String outPath = Environment.getExternalStorageDirectory()
+ File.separator + "ZipTest.apk";
File inFile = new File(inPath);
File outFile = new File(outPath);
ZipInputStream inZip = null;
ZipOutputStream outZip = null;
try {
inZip = new ZipInputStream(new BufferedInputStream(
new FileInputStream(inFile)));
outZip = new ZipOutputStream(new BufferedOutputStream(
new FileOutputStream(outFile)));
ZipEntry entry = null;
byte[] buffer = new byte[1024];
while ((entry = inZip.getNextEntry()) != null) {
Log.v("entry name = ", entry.getName());
outZip.putNextEntry(entry);
int size = 0;
while ((size = inZip.read(buffer, 0, buffer.length)) != -1) {
outZip.write(buffer, 0, size);
}
outZip.closeEntry();
}
outZip.close();
inZip.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
