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);
}
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);
}
相关文章推荐
- Qt5-MSVC2012-qDebug中文乱码解决方法
- 两排滚动js
- git 常用命令
- Drawable资源——Scale Drawable 规模可绘制
- Hadoop新手学习指导之hadoop核心知识学习
- 自定义ScrollView实现阻尼效果(类似于QQ下拉一段距离)
- Swift -- 3.运算符与表达式
- 形态学操作
- MySQL Data source rejected establishment of connection, message from server: "Too many connections"
- android test review
- 使用Git Extensions简单入门Git
- IO编程
- Rails 4 - Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded
- 调整图像- 自动对比度、自动色阶算法
- 两列自适应布局的4种思路
- C++;每周一些题(1)
- 深入理解Linux内核day06--进程调度
- Android性能优化典范(五)
- split一些简单的分隔(js)
- 存储过程 使用解说简介