今天就跟大家聊聊有關(guān)Android系統(tǒng)工具類有哪些,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
吉隆ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
系統(tǒng)工具類
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òng)彈出軟鍵盤 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系統(tǒng)版本 public static String getSystemVersion() { return android.os.Build.VERSION.RELEASE; } //獲取設(shè)備機(jī)型 public static String getSystemModel() { return android.os.Build.MODEL; } //獲取IMEI識(shí)別號(hào) //所需權(quán)限@SuppressLint("MissingPermission") public static String getIMEI(Activity activity) { //6.0以上的系統(tǒng)動(dòng)態(tài)添加權(quán)限 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(); } //獲取系統(tǒng)當(dāng)前語言 public static String getSystemLanguage() { return Locale.getDefault().getLanguage(); } //獲取設(shè)備電量 @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); } //獲取設(shè)備內(nèi)存可用大小(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); } //獲取設(shè)備內(nèi)存可用的總量大小(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); } //重啟設(shè)備 private void restartDevices() { String cmd = "su -c reboot"; try { Runtime.getRuntime().exec(cmd); } catch (IOException e) { Log.i("restart","權(quán)限不足"); } } }
系統(tǒng)相關(guān)權(quán)限
//寫入外部存儲(chǔ) android.permission.WRITE_EXTERNAL_STORAGE,允許寫入外部存儲(chǔ) //讀取外部存儲(chǔ) android.permission.READ_EXTERNAL_STORAGE,允許讀取外部存儲(chǔ) //讀取系統(tǒng)日志 android.permission.READ_LOGS,讀取系統(tǒng)底層日志 //讀取短信內(nèi)容 android.permission.READ_SMS,讀取短信內(nèi)容 //振動(dòng) android.permission.VIBRATE,允許振動(dòng) //重啟設(shè)備 android.permission.REBOOT,允許程序重新啟動(dòng)設(shè)備 //安裝應(yīng)用程序 android.permission.INSTALL_PACKAGES,允許程序安裝應(yīng)用 //修改聲音 android.permission.MODIFY_AUDIO_SETTINGS,修改聲音設(shè)置信息 //錄音 android.permission.RECORD_AUDIO,錄制聲音通過手機(jī)或耳機(jī)的麥克 //使用閃光燈 android.permission.FLASHLIGHT,允許訪問閃光燈 //訪問網(wǎng)絡(luò) android.permission.INTERNET,訪問網(wǎng)絡(luò)連接,可能產(chǎn)生GPRS流量 //改變wifi狀態(tài) android.permission.CHANGE_WIFI_STATE,打開wifi,改變wifi狀態(tài) //獲取WiFi狀態(tài) android.permission.ACCESS_WIFI_STATE,獲取當(dāng)前WiFi接入的狀態(tài)以及WLAN熱點(diǎn)的信息 //獲取網(wǎng)絡(luò)狀態(tài) android.permission.ACCESS_NETWORK_STATE,獲取網(wǎng)絡(luò)信息狀態(tài),如當(dāng)前的網(wǎng)絡(luò)連接是否有效 //拍照權(quán)限 android.permission.CAMERA,允許訪問攝像頭進(jìn)行拍照 //使用藍(lán)牙 android.permission.BLUETOOTH,允許程序連接配對(duì)過的藍(lán)牙設(shè)備 //電池狀態(tài) android.permission.BATTERY_STATS,允許應(yīng)用程序獲取電池狀態(tài)的權(quán)限
看完上述內(nèi)容,你們對(duì)Android系統(tǒng)工具類有哪些有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。