android 几个工具方法
集合几个工具方法,方便以后使用。
1.获取手机 分辨率屏幕:
- public static void printScreenInfor(Context context){
- DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
- int width = displayMetrics.widthPixels;
- int height = displayMetrics.heightPixels;
- float density = displayMetrics.density;
- float scaledDensity = displayMetrics.scaledDensity;
- Log.d(null, String.format("screen info: width = %d, height = %d, density = %f , scaledDensity = %f ", width, height, density, scaledDensity));
- }
2.获取手机 密度
- public static double getDensity(Activity context) {
- DisplayMetrics displaysMetrics = new DisplayMetrics();
- if(context == null ){
- LogHelper.e(LogHelper.APPUTIL, "传入的应为activity");
- return 0;
- }
- context.getWindowManager().getDefaultDisplay().getMetrics(displaysMetrics);
- float density = displaysMetrics.scaledDensity;
- return density;
- }
3.获取手机的dp和px转化:
- public static int dip2px(Context context, float dipValue) {
- final float scale = context.getResources().getDisplayMetrics().density;
- return (int) (dipValue * scale + 0.5f);
- }
- public static int px2dip(Context context, float pxValue) {
- final float scale = context.getResources().getDisplayMetrics().density;
- return (int) (pxValue / scale + 0.5f);
- }
4.获取手机真实的物理尺寸
- public static double getScreenPhysicalSize(Activity activity) {
- DisplayMetrics dm = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
- double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2));
- return diagonalPixels / (160 * dm.density);
- }
5.判断手机是否是平板
- public static boolean isTablet(Context context) {
- return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
- }
6.获取手机的编译版本 制造厂商等
- String osVersion = android.os.Build.VERSION.SDK;//编译版本
- String model = Build.MODEL;//手机品牌
- String manufacture = Build.manufacture;//
- String cpu = Build.cpu_ABI;
7.获取手机mac地址等
- public String getLocalMacAddress() {
- WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- WifiInfo info = wifi.getConnectionInfo();
- return info.getMacAddress();
- }
8.判断是有网络
- public static boolean isNetworkAvailable(Context context) {
- boolean flag = false;
- if (context != null) {
- ConnectivityManager connMgr = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
- if (networkInfo != null && networkInfo.isConnected()) {
- flag = true;
- }
- }
- return flag;
- }
9.其他待补充
android 几个工具方法的更多相关文章
- Android Studio更新升级方法
自从2013 Google I/O大会之后,笔者就将android ide开发工具从eclipse迁移到Android Studio了,android studio一直在更新完善,为了与时俱进,我们当 ...
- Xamarin For Visual Studio 3.0.54.0 完整离线破解版(C# 开发Android、IOS工具 吾乐吧软件站分享)
Xamarin For Visual Studio就是原本的Xamarin For Android 以及 Xamarin For iOS,最新版的已经把两个独立的插件合并为一个exe安装包了.为了区分 ...
- Xamarin Mono For Android 4.6.07004 完整离线安装破解版(C#开发Android、IOS工具)
Xamarin是由Miguel de Icaza成立的一家新的独立公司,目的是给Mono一个继续奋斗的机会.Mono for Android (原名:MonoDroid)可以让开发人员使用 Mic ...
- Android开发常用工具类
来源于http://www.open-open.com/lib/view/open1416535785398.html 主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前 ...
- Android Studio更新升级方法(转)
自从2013 Google I/O大会之后,笔者就将android ide开发工具从eclipse迁移到Android Studio了,android studio一直在更新完善,为了与时俱进,我们当 ...
- Android各种获取Context方法
首先讲一讲这四个函数的区别,后面还有我对context的一些理解区别如下所示: 原文链接http://stackoverflow.com/questions/6854265/getapplicatio ...
- Android 代码检查工具SonarQube
http://blog.csdn.net/rain_butterfly/article/details/42170601 代码检查工具能帮我们检查一些隐藏的bug,代码检查工具中sonar是比较好的一 ...
- 正确使用Android性能分析工具——TraceView
http://blog.jobbole.com/78995/ 首页 最新文章 IT 职场 前端 后端 移动端 数据库 运维 其他技术 - 导航条 - 首页 最新文章 IT 职场 前端 - Ja ...
- Android中日志工具的使用
添加LogCat到你的Eclipse日志在任何项目的开发过程中都会起到非常重要的作用,在Android项目中如果你想要查看日志则必须要使用LogCat工具.当你第一次在Eclipse中运行Androi ...
随机推荐
- BZOJ3143:[HNOI2013]游走(高斯消元)
Description 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点, ...
- AlexNet 分类 FashionMNIST
from mxnet import gluon,init,nd,autograd from mxnet.gluon import data as gdata,nn from mxnet.gluon i ...
- [19/03/26-星期二] 容器_Map(图、键值对、映射)接口之HashMap(散列映射)&TreeMap(树映射)
一.概念&方法 现实生活中,我们经常需要成对存储某些信息.比如,我们使用的微信,一个手机号只能对应一个微信账户,这就是一种成对存储的关系. Map就是用来存储“键(key)-值(value) ...
- XXE攻防——XML外部实体注入
XXE攻防——XML外部实体注入 转自腾讯安全应急响应中心 一.XML基础知识 XML用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的 ...
- P2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver
P2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver 最大化一个子矩阵的和. 我们如何去做,dp和贪心呀! 大体题意:给定一个正方形,然后在正方形中求出一个大小已经给定的 ...
- 【Node.js】Jade视图模板的使用
跟MVC里面的Rezor做差不多的事儿,但是比Rezor弱了一些,比较不喜欢CoffeeScript.Jade这种靠缩进来维系层级结构的做法,就好比接受不了c#中if下面只有一句很长的代码,但是却不加 ...
- Css animation 与 float 、flex 布局问题
1. 有这样一段css html 代码 <div class="container"> <div class="float-left"> ...
- __doPostBack 方法解析
function __doPostBack(eventTarget, eventArgument)的eventTarget参数是引起回送的控件的ID,eventArgument参数是回调参数(与控件相 ...
- CSS之元素
CSSS书写位置 内嵌式 <head> <style type = "text/css"> **** </style> </head> ...
- DB数据源之SpringBoot+MyBatis踏坑过程(六)mysql中查看连接,配置连接数量
DB数据源之SpringBoot+MyBatis踏坑过程(六)mysql中查看连接,配置连接数量 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之SpringBoot+Mybati ...