您的位置:首页 > 其它

apk自动安装 取得apk版本号 点击退出两次退出程序

2016-05-03 14:33 603 查看
//打开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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: