public static void Install(Context ctx, String strLocalFile) {
Intent intentInstall = new Intent();
String apkPath = "/data/data/" + ctx.getPackageName() + "/files";
String apkName = "yuan.apk";
File file = new File(apkPath, apkName);
try {
//assets下对于超过2M 的文件,有所限制,建议改名为Jpg
InputStream is = ctx.getAssets().open("yuan.apk");
if (!file.exists()) {
file.createNewFile();
FileOutputStream os = ctx.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.e("", "----------- has been copy to ");
} else {
Log.e("", "-----------cunzai ");
}
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.e("", e.toString());
}
Log.e("", "fl--" + file.getName() + "-dd---" + file.getAbsolutePath()
+ "-pa-" + file.getPath());
intentInstall.setAction(android.content.Intent.ACTION_VIEW);
intentInstall.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
intentInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intentInstall);
}
当然代码大部分参考其他人的,请见谅
同时请参考http://ccsosnfs.iteye.com/blog/1390405