您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關Android系統工具類有哪些,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
系統工具類
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識別號 //所需權限 <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.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系統工具類有哪些有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。