Android 系统工具类

Android 系统工具类,第1张

概述public class systemUtil { //隐藏ipad底部虚拟按键栏 @RequiresApi(api = Build.VERSION_CODES.KITKAT) public static void closeBottomBar(Activity activity){ Window _window = activity.getWindow(
public class systemUtil {    //隐藏ipad底部虚拟按键栏    @RequiresAPI(API = Build.VERSION_CODES.KITKAT)    public static voID closeBottombar(Activity activity){        Window _window = activity.getwindow();        WindowManager.LayoutParams params = _window.getAttributes();        params.systemUIVisibility =                VIEw.SYstem_UI_FLAG_HIDE_NAVIGATION|VIEw.SYstem_UI_FLAG_IMMERSIVE;        _window.setAttributes(params);    }    //不自动d出软键盘    public static voID softinputMode(Activity activity){        activity.getwindow().setSoftinputMode(                WindowManager.LayoutParams.soFT_input_ADJUST_RESIZE |                WindowManager.LayoutParams.soFT_input_STATE_HIDDEN);    }    //保持屏幕常亮    public static voID screenlightUp(Activity activity){        activity.getwindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);    }    //获取屏幕分辨率    public static int[] defaultdisplay(Activity activity){        int[] pixels = new int[2];        displayMetrics dm = new displayMetrics();        activity.getwindowManager().getDefaultdisplay().getMetrics(dm);        pixels[0]=dm.wIDthPixels;        pixels[1]=dm.heightPixels;        return pixels;    }    //获取AndroID系统版本    public static String getSystemVersion() {        return androID.os.Build.VERSION.RELEASE;    }    //获取设备机型    public static String getSystemModel() {        return androID.os.Build.MODEL;    }    //获取IMEI识别号    //所需权限 <uses-permission androID:name="androID.permission.READ_PHONE_STATE" />    @Suppresslint("MissingPermission")    public static String getIMEI(Activity activity) {        //6.0以上的系统动态添加权限        if (ActivityCompat.checkSelfPermission(activity,Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {            ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.READ_PHONE_STATE},1);        }        TelephonyManager tm =                (TelephonyManager) activity.getSystemService(Activity.TELEPHONY_SERVICE);        return tm.getdeviceid();    }    //获取系统当前语言    public static String getSystemLanguage() {        return Locale.getDefault().getLanguage();    }    //获取设备电量    @TargetAPI(Build.VERSION_CODES.LolliPOP)    public static int getBattery(Context context){        BatteryManager batteryManager =                (BatteryManager)context.getSystemService(BATTERY_SERVICE);        return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);    }    //获取设备内存可用大小(GB)    public static String getRomAvailableSize(Context context) {        file path = Environment.getDataDirectory();        StatFs stat = new StatFs(path.getPath());        long blockSize = stat.getBlockSize();        long availableBlocks = stat.getAvailableBlocks();        return Formatter.formatfileSize(context,blockSize * availableBlocks);    }    //获取设备内存可用的总量大小(GB)    public static String getRomTotalSize(Context context) {        file path = Environment.getDataDirectory();        StatFs stat = new StatFs(path.getPath());        long blockSize = stat.getBlockSize();        long totalBlocks = stat.getBlockCount();        return Formatter.formatfileSize(context,blockSize * totalBlocks);    }    //获得SD卡可用总量大小    public static String getSDTotalSize(Context context) {        file path = Environment.getExternalStorageDirectory();        StatFs stat = new StatFs(path.getPath());        long blockSize = stat.getBlockSize();        long totalBlocks = stat.getBlockCount();        return Formatter.formatfileSize(context,blockSize * totalBlocks);    }    //获得sd卡可用大小    private String getSDAvailableSize(Context context) {        file path = Environment.getExternalStorageDirectory();        StatFs stat = new StatFs(path.getPath());        long blockSize = stat.getBlockSize();        long availableBlocks = stat.getAvailableBlocks();        return Formatter.formatfileSize(context,blockSize * availableBlocks);     }    //重启设备    private voID restartDevices() {        String cmd = "su -c reboot";        try {            Runtime.getRuntime().exec(cmd);        } catch (IOException e) {            Log.i("restart","权限不足");        }    }}
总结

以上是内存溢出为你收集整理的Android 系统工具类全部内容,希望文章能够帮你解决Android 系统工具类所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1086440.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存