Android开发基础知识回顾
来源:互联网 发布:专业淘宝图片拍摄德州 编辑:程序博客网 时间:2024/05/22 00:23
1.获取版本信息
public static String getVersionName(Context context) {String versionName;// 获取包管理器PackageManager packageManager = context.getPackageManager();try { PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); versionName = packageInfo.versionName;} catch (NameNotFoundException e) { versionName = "获取版本信息错误"; e.printStackTrace();}return versionName;}
2.获取服务器版本信息
class GetServerVisionRunnable implements Runnable { @Override public void run() { InputStream is = null; BufferedReader br = null; try { // 创建连接 HttpURLConnection connection = (HttpURLConnection) new URL( "http://192.168.129.102:8080/version.json").openConnection(); // 设置连接超时时间 connection.setConnectTimeout(5000); // 设置读取超时时间 connection.setReadTimeout(5000); // 连接 connection.connect(); String result = ""; if (connection.getResponseCode() == 200) { is = connection.getInputStream(); br = new BufferedReader(new InputStreamReader(is)); String readlline; while ((readlline = br.readLine()) != null) { result += readlline; } JSONObject json = new JSONObject(result); int serverVersionCode = json.optInt("versioncode"); } } catch (Exception e) { e.printStackTrace(); } finally { CommonUtils.CloseStream(is); CommonUtils.CloseStream(br); } } }
3.下载、安装apk
class DownloadRunnable implements Runnable { private InputStream inputStream; private FileOutputStream fos; private ProgressDialog pd; public DownloadRunnable(ProgressDialog pd) { this.pd = pd; } @Override public void run() { try { // 初始化 HttpURLConnection connection = (HttpURLConnection) new URL(downUrl).openConnection(); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.connect(); // 连接成功 if (connection.getResponseCode() == 200) { // 创建文件 File file = new File(Environment.getExternalStorageDirectory(), "test.apk"); inputStream = connection.getInputStream(); // 获取文件总长度 int totalLength = connection.getContentLength(); // 设置进度条的总大小 pd.setMax(totalLength); fos = new FileOutputStream(file); int len; byte[] buffer = new byte[1024]; int current = 0; while ((len = inputStream.read(buffer)) != -1) { fos.write(buffer, 0, len); current += len; // 设置进度条的进度 pd.setProgress(current); } // 隐藏进度条 pd.dismiss(); // 安装应用 Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory("android.intent.category.DEFAULT"); intent.setDataAndType(Uri.parse("file:" + file.getAbsolutePath()), "application/vnd.android.package-archive"); startActivityForResult(intent, REQ_CODE_INSTALL_APP); } } catch (Exception e) { e.printStackTrace(); } finally { CommonUtils.CloseStream(inputStream); CommonUtils.CloseStream(fos); } }}
4.动画
//沿Y轴旋转的属性动画 ObjectAnimator animator = ObjectAnimator.ofFloat(iv_icon, "rotationY", 0, 45, 90, 135, 180, 225, 270, 315, 360); // 时常 animator.setDuration(2000); // 重复次数 animator.setRepeatCount(ObjectAnimator.INFINITE); // 重复模式 animator.setRepeatMode(ObjectAnimator.REVERSE); animator.start();
5.按钮按压效果选择器
在res/drawable/目录下新建一个正常状态下的shape
阅读全文
0 0
- Android开发基础知识回顾
- Android基础知识回顾之Activity
- Android系统回顾(一):Android基础知识
- Android系统回顾(二):Android基础知识
- Android基础知识回顾---进程的优先级
- android基础知识回顾--ContentProvider简单用法
- 基础知识回顾
- 前端开发入门:html和css基础知识回顾
- 前端开发入门:html和css基础知识回顾2
- Android网络开发基础知识
- Android 开发基础知识 Timer
- Android 开发基础知识
- Android开发---JNI基础知识
- Android开发基础知识
- Android网络开发基础知识
- Android音频开发:基础知识
- Android开发的基础知识
- Android 开发基础知识
- 泛型的学习及使用
- linux文件时间属性 查看和修改文件时间
- MarkDown常用语法
- python笔记4
- 计算机的发展阶段
- Android开发基础知识回顾
- 我为什么选择产品经理
- NOIP2015 运输计划
- 个人总结19
- 不同路径-LintCode
- 携程的学习及使用
- Android Studio – Cannot resolve symbol ‘R’
- 机器学习系列二
- C++ 对指针的理解