收集Android常用工具类,方便查阅
2016-09-08 12:15
357 查看
//直接拨打电话,需要权限 public static void gotoCallPhone(Context context,String tel) { Intent intent = new Intent(Intent.ACTION_CALL); Uri data = Uri.parse("tel:" + tel); intent.setData(data); context.startActivity(intent); } //跳转到拨打电话界面 public static void gotoDialPhone(Context context,String tel) { Intent intent = new Intent(Intent.ACTION_DIAL); Uri data = Uri.parse("tel:" + tel); intent.setData(data); context.startActivity(intent); } //String double类型转换 public static double parseDouble(String dString) { try { return Double.parseDouble(dString); } catch (Exception e) { return 0f; } } //String float 类型转换 public static float parseFloat(String fString) { try { return Float.parseFloat(fString); } catch (Exception e) { return 0f; } } //手机IEMI获取 public static String getIEMI() { TelephonyManager telephonyManager = (TelephonyManager) getApplication().getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getDeviceId(); } //dp转px public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } //px转dp public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } //sp转dp public static int sp2px(Context context, float spValue) { final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; return (int) (spValue * fontScale + 0.5f); } //获取屏幕高度 Activity.getWindowManager() public static int getScreenHight(WindowManager windowManager) { return windowManager.getDefaultDisplay().getHeight(); } //获取屏幕宽度 Activity.getWindowManager() public static int getScreenWidth(WindowManager windowManager) { return windowManager.getDefaultDisplay().getWidth(); } //获取系统时间 public static String getSysTime() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date curDate = new Date(System.currentTimeMillis());//获取当前时间 return formatter.format(curDate); } //手动进行GC public static void GC() { System.gc(); } //app下载的图片有时在系统的相册里没有缩列图,此方法可以让其生成缩列图,未验证 public static void updateGallery(Context context) { Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); //MediaStore.Images.Media.EXTERNAL_CONTENT_URI String path = Environment.getExternalStorageDirectory() + "/DCIM/Camera"; Uri uri = Uri.fromFile(new File(path)); intent.setData(uri); context.sendBroadcast(intent); } //递归删除所有文件 public static void deleteAllFiles(File file) { if (file.isFile()) { file.delete(); return; } if (file.isDirectory()) { File[] childFile = file.listFiles(); if (childFile == null || childFile.length == 0) { file.delete(); return; } for (File f : childFile) { deleteAllFiles(f); } file.delete(); } } //随机数+时间取文件名 public static String getFileName(String header,String format) { return header + ((int) (Math.random() * 100000 + 1)) + String.valueOf(System.currentTimeMillis()) + format; }
相关文章推荐
- ios开发总结:Utils常用方法等收集,添加扩展类,工具类方法,拥有很多方便快捷功能(不断更新中。。。)
- 史上最全的常用开发工具类收集Android
- Android常用工具类收集、Trinea的博客
- c#、js、java常用语句收集【自用,方便查阅】
- Android开发人员不得不收集的代码(常用的工具类)
- 网上收集的关于Android uses-permission的资料,方便查找
- Android 常用缩写方便记忆( continue to)
- android 常用语句收集
- Android的一本很好的英文原著Andbook 我手动将其翻译了 方便以后查阅
- Android常用代码(类似工具类吧)
- 常用键盘ASCⅡ码,方便查阅
- 常用的正则表达式.网上拷贝,方便自己查阅.
- 数据库零碎---常用的mysql命令,收藏了,方便查阅
- 常用键盘ASCⅡ码,方便查阅!
- android常用工具类 andutils
- Android常用的工具类-收藏用
- Android 常用代码段收集(不断更新)(都经过了姐的试验认证的)
- asp 收集的资料了,为了方便查阅。
- zdz工具箱v1.5 android版本发布了,集成各种个人生活中常用的工具,方便日常使用管理
- Android中常用工具类