Java常用工具方法
摘要:1.计算文件大小,并按**B,*KB,**MB,**GB格式返回字符串/** * 文件大小格式转换 * @param fileS 文件大小 * @return 文件大小 */ public static String FormetFileSize(long fileS) { // 转换文件大小 DecimalFormat df = new DecimalFormat("#.00"); String fileSizeString = ""; if (fileS < 1024) {...
阅读全文
查询APK是否安装
摘要:/** * 查询系统是否安装packageName的apk */ public static boolean isInstallApk(Context context, String packageName) { PackageManager packageManager = context.getPackageManager(); java.util.List<PackageInfo> apps = new ArrayList<PackageInfo>(); apps = packageManager.getInstalledPackage...
阅读全文
获取Android当前显示(最外层)的Activity的全名
摘要:1 public static String getTopActivityComponet(Context context) 2 { 3 try { 4 ActivityManager am = (ActivityManager) context 5 .getSystemService(Context.ACTIVITY_SERVICE); 6 ComponentName cn = am.getRunningTasks(1).get(0).topActivity; 7 re...
阅读全文
获取txt文件编码
摘要:获取txt文档的编码方式,亲测可用。public static String getCharset(File file) { String charset = "GBK"; // 默认编码 byte[] first3Bytes = new byte[3]; try { boolean checked = false; BufferedInputStream bis = new BufferedInputStream( new FileInputStream(file)); ...
阅读全文
Android图片缩放、圆角处理以及倒影特效代码
摘要:public class ImageUtil { //缩放图片 public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float)w/width); float scaleHeight = ((float)h/height); matrix.postScale(scaleHeight...
阅读全文
Android私有数据内部存储方法
摘要:本节介绍这个存储私有数据的 API,它使用 android.content.Context.openFileInput、openFileOutput 和 getCacheDir() 来高速缓存数据,当用户卸载掉应用程序时,这些文件就会被移除。存储数据至内部私有存储器:/** * Writes content to internal storage making the content private to * the application. The method can be easily changed to take the MODE * as argument and let t...
阅读全文