//打开APK安装程序代码
private void openFile(File file) {
// TODO Auto-generated method stub
Log.e("OpenFile", file.getName());
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(intent);
}
//获得apk 版本信息
public static int getAPPVersionCodeFromAPP(Context ctx) {
int currentVersionCode = 0;
PackageManager manager = ctx.getPackageManager();
try {
PackageInfo info = manager.getPackageInfo(ctx.getPackageName(), 0);
String appVersionName = info.versionName; // 版本名
currentVersionCode = info.versionCode; // 版本号
System.out.println(currentVersionCode + " " + appVersionName);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch blockd
e.printStackTrace();
}
return currentVersionCode;
}
//点击退出两次退出程序
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
finish();
}
return true;
}
return super.onKeyDown(keyCode, event);
}