Android极速开发之设备管理器 发表于 2016-09-03 | 分类于 Android , Android极速开发 | | 阅读次数 继续来总结一些常用封装。 欢迎留言、转发、打赏 项目源码参考地址 点我点我–欢迎Start 阅读全文 »
Android极速开发之手机屏幕 发表于 2016-08-27 | 分类于 Android , Android极速开发 | | 阅读次数 获取屏幕宽高 手机横竖屏的判断 123456789101112131415161718public class ScreenUtils { public static int getWidth(Context context) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; } public static int getHeight(Context context) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.heightPixels; }} 123456789101112131415161718public class ConfigUtils { public static boolean isOrientationPortrait(Context context) { if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { return true; } return false; } public static boolean isOrientationLandscape(Context context) { if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { return true; } return false; }}
Android极速开发之调节屏幕的亮度 发表于 2016-08-27 | 分类于 Android , Android极速开发 | | 阅读次数 屏幕亮度调节 123456789101112131415161718192021222324252627//设置应用中的亮度 不保存 public void Brightness(View view){ boolean autoBrightness = BrightnessTools.isAutoBrightness(getContentResolver()); if (autoBrightness) { T.showLong(this, "关闭自动调节亮度"); BrightnessTools.stopAutoBrightness(this); } BrightnessTools.setBrightness(this, 255); T.showLong(this, "亮度已经设置为了最大"); } //获取当前亮度 并设置最大的亮度保存 public void saveBrightness(View view){ int screenBrightness = BrightnessTools.getScreenBrightness(this); T.showLong(this, "当前屏幕亮度为:"+screenBrightness); BrightnessTools.saveBrightness(getContentResolver(), 255); } //开启关闭自动调节亮度 public void offAuto(View view){ boolean autoBrightness = BrightnessTools.isAutoBrightness(getContentResolver()); if (autoBrightness) { T.showLong(this, "关闭自动调节亮度"); BrightnessTools.stopAutoBrightness(this); }else { T.showLong(this, "开启自动调节亮度"); BrightnessTools.startAutoBrightness(this); } } 阅读全文 »
Android极速开发之SD卡缓存目录 发表于 2016-08-27 | 分类于 Android , Android极速开发 | | 阅读次数 读取某个文件夹中的所有Apk文件路径并打开安装页面 读取某文件夹下的所有apk文件 获取SD卡跟目录中的某个文件 弹出安装界面 卸载apk 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114/** * * @author Javen * */public class SDKUtil { private final static String TAG=SDKUtil.class.getSimpleName(); /** * 读取某个文件夹中的所有Apk文件路径并打开安装页面 * @param context * @param path */ public static void readApkAndStart(Context context,String path){ List<String> listpath = readAllApkForPath(context, path); if (listpath!=null && listpath.size()>0) { for (String string : listpath) { SDKUtil.openInstallView(context, string); } }else { L.e("xxxx-----", "readApkAndStart null。。。。。。。"); } } /** * 读取某文件夹下的所有apk文件 * @param context * @param path * @return */ public static List<String> readAllApkForPath(Context context,String path){ List<String> fileNameList=new ArrayList<String>(); File dir; if (Parameter.isDebug) { dir = getSDir(context, path); }else { dir = getDiskCacheDir(context, path); } if (dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { String filePath = file.getAbsolutePath(); if (filePath.endsWith(".apk")) { fileNameList.add(filePath); } } return fileNameList; } return null; } /** * 获取SD卡跟目录中的某个文件 * @param context * @param uniqueName * @return */ public static File getSDir(Context context, String uniqueName) { boolean externalStorageAvailable = Environment .getExternalStorageState().equals(Environment.MEDIA_MOUNTED); String path = null; if (externalStorageAvailable) { path=Environment.getExternalStorageDirectory().getAbsolutePath(); } return new File(path + File.separator + uniqueName); } /** * 获取缓存地址 * @param context * @param uniqueName * @return */ public static File getDiskCacheDir(Context context, String uniqueName) { boolean externalStorageAvailable = Environment .getExternalStorageState().equals(Environment.MEDIA_MOUNTED); String cachePath; if (externalStorageAvailable) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } L.i(TAG, cachePath); return new File(cachePath + File.separator + uniqueName); } /** * 弹出安装界面 * @param context * @param pathString apk 路径 */ public static void openInstallView(Context context,String pathString){ //启动安装界面// Intent install = new Intent(Intent.ACTION_VIEW);// install.setDataAndType(Uri.fromFile(new File(pathString)),// "application/vnd.android.package-archive");// install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// context.startActivity(install); ApkController.install(pathString, context); } /** * 卸载apk * @param context * @param packageName */ public static void uninstallApk(Context context, String packageName) { Uri uri = Uri.parse("package:" + packageName); Intent intent = new Intent(Intent.ACTION_DELETE, uri); context.startActivity(intent); } }