Android系統(tǒng)工具類(lèi)詳解
本文實(shí)例為大家分享了Android系統(tǒng)工具類(lèi)的具體代碼,供大家參考,具體內(nèi)容如下
系統(tǒng)工具類(lèi)
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)彈出軟鍵盤(pán) 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)限 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> @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)前語(yǔ)言 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)限
//寫(xiě)入外部存儲(chǔ) android.permission.WRITE_EXTERNAL_STORAGE,允許寫(xiě)入外部存儲(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,錄制聲音通過(guò)手機(jī)或耳機(jī)的麥克 //使用閃光燈 android.permission.FLASHLIGHT,允許訪(fǎng)問(wèn)閃光燈 //訪(fǎng)問(wèn)網(wǎng)絡(luò) android.permission.INTERNET,訪(fǎng)問(wèn)網(wǎng)絡(luò)連接,可能產(chǎn)生GPRS流量 //改變wifi狀態(tài) android.permission.CHANGE_WIFI_STATE,打開(kāi)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,允許訪(fǎng)問(wèn)攝像頭進(jìn)行拍照 //使用藍(lán)牙 android.permission.BLUETOOTH,允許程序連接配對(duì)過(guò)的藍(lán)牙設(shè)備 //電池狀態(tài) android.permission.BATTERY_STATS,允許應(yīng)用程序獲取電池狀態(tài)的權(quán)限
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android系統(tǒng)添加Linux驅(qū)動(dòng)
- Android實(shí)現(xiàn)EditText添加下劃線(xiàn)
- Android添加用戶(hù)組及自定義App權(quán)限的方法
- Android中多行文本末尾添加圖片排版問(wèn)題的解決方法
- Android添加指紋解鎖功能的實(shí)現(xiàn)代碼
- Android實(shí)現(xiàn)添加商品到購(gòu)物車(chē)動(dòng)畫(huà)效果
- Android GridView仿微信添加多圖效果
- Android中recyclerView底部添加透明漸變效果
- Android GridView添加頭部問(wèn)題的解決
- 詳解如何在A(yíng)ndroid Studio中添加RecyclerView-v7支持包
- Android百度地圖添加Marker失真問(wèn)題的解決方案
- Android手機(jī)屏幕同步工具asm.jar
- Android中APK簽名工具之jarsigner和apksigner詳解
- 超實(shí)用的android網(wǎng)絡(luò)工具類(lèi)
- Android編程實(shí)現(xiàn)將時(shí)間轉(zhuǎn)化成幾分鐘前、幾天前等形式的工具類(lèi)
- Android系統(tǒng)添加自己寫(xiě)的工具
相關(guān)文章
Android自定義View實(shí)現(xiàn)旋轉(zhuǎn)的圓形圖片
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)旋轉(zhuǎn)的圓形圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Android檢查網(wǎng)絡(luò)狀態(tài)工具類(lèi)詳解
這篇文章主要為大家詳細(xì)介紹了Android檢查網(wǎng)絡(luò)狀態(tài)工具類(lèi),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04Android 創(chuàng)建與解析XML(四)——詳解Pull方式
本篇文章主要介紹了Android創(chuàng)建與解析XML(二)——詳解Pull方式,這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。2016-11-11Android用戶(hù)注冊(cè)界面簡(jiǎn)單設(shè)計(jì)
這篇文章主要為大家分享了Android用戶(hù)注冊(cè)界面簡(jiǎn)單設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android實(shí)現(xiàn)繪制折線(xiàn)圖APP代碼
大家好,本篇文章主要講的是Android實(shí)現(xiàn)繪制折線(xiàn)圖APP代碼,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話(huà)記得收藏一下2022-02-02Android仿QQ個(gè)人標(biāo)簽添加與刪除功能
這篇文章主要為大家詳細(xì)介紹了Android仿QQ個(gè)人標(biāo)簽添加與刪除功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12Android M(6.x)使用OkHttp包解析和發(fā)送JSON請(qǐng)求的教程
Android 6.0采用的SPDY支持HTTP上GZIP壓縮的傳輸,這使得OkHttp包的功能能夠進(jìn)一步被利用,本文我們來(lái)總結(jié)一下Android M(6.0)使用OkHttp包解析和發(fā)送JSON請(qǐng)求的教程2016-07-07Andriod Service與Thread的區(qū)別介紹
我們要明確Service是運(yùn)行在主線(xiàn)程的,不能有耗時(shí)操作,這樣,在Service中處理耗時(shí)操作的時(shí)候,我們依然需要使用線(xiàn)程來(lái)處理,既然在Service里也要?jiǎng)?chuàng)建一個(gè)子線(xiàn)程,那為什么不直接在A(yíng)ctivity里創(chuàng)建呢,下面通過(guò)本文給大家介紹Andriod Service與Thread的區(qū)別,一起看看吧2017-04-04Android Bitmap和Drawable相互轉(zhuǎn)換的簡(jiǎn)單代碼
Android Bitmap和Drawable相互轉(zhuǎn)換的簡(jiǎn)單代碼,需要的朋友可以參考一下2013-05-05