Android系统工具类有哪些
今天就跟大家聊聊有关Android系统工具类有哪些,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
吉隆ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
系统工具类
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); } //不自动弹出软键盘 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识别号 //所需权限@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.permission.WRITE_EXTERNAL_STORAGE,允许写入外部存储 //读取外部存储 android.permission.READ_EXTERNAL_STORAGE,允许读取外部存储 //读取系统日志 android.permission.READ_LOGS,读取系统底层日志 //读取短信内容 android.permission.READ_SMS,读取短信内容 //振动 android.permission.VIBRATE,允许振动 //重启设备 android.permission.REBOOT,允许程序重新启动设备 //安装应用程序 android.permission.INSTALL_PACKAGES,允许程序安装应用 //修改声音 android.permission.MODIFY_AUDIO_SETTINGS,修改声音设置信息 //录音 android.permission.RECORD_AUDIO,录制声音通过手机或耳机的麦克 //使用闪光灯 android.permission.FLASHLIGHT,允许访问闪光灯 //访问网络 android.permission.INTERNET,访问网络连接,可能产生GPRS流量 //改变wifi状态 android.permission.CHANGE_WIFI_STATE,打开wifi,改变wifi状态 //获取WiFi状态 android.permission.ACCESS_WIFI_STATE,获取当前WiFi接入的状态以及WLAN热点的信息 //获取网络状态 android.permission.ACCESS_NETWORK_STATE,获取网络信息状态,如当前的网络连接是否有效 //拍照权限 android.permission.CAMERA,允许访问摄像头进行拍照 //使用蓝牙 android.permission.BLUETOOTH,允许程序连接配对过的蓝牙设备 //电池状态 android.permission.BATTERY_STATS,允许应用程序获取电池状态的权限
看完上述内容,你们对Android系统工具类有哪些有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
当前题目:Android系统工具类有哪些
网页地址:http://scyingshan.cn/article/gcpdoc.html