publicstaticvoidInstall(Context?ctx,?String?strLocalFile)?{
Intent?intentInstall=newIntent();
String?apkPath="/data/data/"+ctx.getPackageName()+"/files";
String?apkName="yuan.apk";
File?file=newFile(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=newbyte[512];inti=-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