apk里安装apk [更新代码]

假设在A apk中放入 B apk,在A apk安装运行后,要安装 B apk

将B apk放在raw目录。

将B apk拷贝至 /data/data/A apk的包名/files


设置B apk的权限。

通过系统安装器安装。

代码随后上



String apkPath = "/data/data/" + getPackageName() + "/files";
String apkName = "b.apk";
File file = new File(apkPath,apkName);

try
{
InputStream is = getResources().openRawResource(R.raw.b);

if(!file.exists())
{
file.createNewFile();

FileOutputStream os = openFileOutput(file.getName(), Context.MODE_WORLD_WRITEABLE);

byte[] bytes = new byte[512];
int i = -1;
while((i = is.read(bytes))>0)
{
os.write(bytes);
}

os.close();
is.close();
Log.d(LOG_TAG, apkName + " has been copy to " + apkPath);
};

String permission="666";

try
{
String command = "chmod " + permission + " " + apkPath + "/" + apkName;
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);
}
catch (IOException e)
{
e.printStackTrace();
}

}
catch(Exception e)
{
Log.d(LOG_TAG, e.toString());
finish();
}

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);




如果apk文件过大,如下
-------------------------------------------------------
http://www.hfdigg.com/SrcShow.asp?Src_ID=10092


android raw文件夹下.db后缀文件大于1M时,拷贝时将会出现:DEBUG/asset(725): Data exceeds UNCOMPRESS_DATA_MAX (1662976 vs 1048576)

出现这个问题的原因是,assetsManager 无法处理大于1M的文件的压缩和解压。
但以下文件类型,因为是已经压缩过的,不会进行压缩处理,如下:
/* these formats are already compressed, or dont compress well */
static const char* kNoCompressExt[] = {
".jpg", ".jpeg", ".png", ".gif",
".wav", ".mp2", ".mp3", ".ogg", ".aac",
".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
".amr", ".awb", ".wma", ".wmv"
};
【解决办法】将Sqlite db文件,先改名为.jpg文件,放在assets中,然后在程序第一次启动时,改名拷贝到/data/data
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值