80,493
社区成员
发帖
与我相关
我的任务
分享
String apkPath = "/data/data/" + mContext.getPackageName() + "/files";
String destapkName = "well.apk";
File file = null;
file = new File(apkPath, destapkName);
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream os = mContext.openFileOutput(file.getName(),
Context.MODE_WORLD_READABLE);
byte[] bytes = new byte[512];
int i = -1;
while ((i = is.read(bytes)) > 0) {
os.write(bytes);
}
os.close();
is.close();
String permission = "666";
try {
String command = "chmod " + permission + " " + apkPath
+ "/" + destapkName;
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
Log.e("----", e.toString());
}
if (DEBUG)
Log.e("",
"fl--" + file.getName() + "----"
+ file.getAbsolutePath() + "---"
+ file.getPath());
if (file != null) {
Intent intentInstall = new Intent();
intentInstall
.setAction(android.content.Intent.ACTION_VIEW);
intentInstall.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
intentInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intentInstall);
}