Android系統(tǒng)工具類詳解
更新時間:2018年08月16日 11:52:14 作者:xixi襲陽
這篇文章主要為大家詳細介紹了Android系統(tǒng)工具類的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Android系統(tǒng)工具類的具體代碼,供大家參考,具體內(nèi)容如下
系統(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);
}
//不自動彈出軟鍵盤
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;
}
//獲取設備機型
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以上的系統(tǒng)動態(tài)添加權限
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)當前語言
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);
}
//獲取設備內(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);
}
//獲取設備內(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);
}
//重啟設備
private void restartDevices() {
String cmd = "su -c reboot";
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
Log.i("restart","權限不足");
}
}
}
系統(tǒng)相關權限
//寫入外部存儲 android.permission.WRITE_EXTERNAL_STORAGE,允許寫入外部存儲 //讀取外部存儲 android.permission.READ_EXTERNAL_STORAGE,允許讀取外部存儲 //讀取系統(tǒng)日志 android.permission.READ_LOGS,讀取系統(tǒng)底層日志 //讀取短信內(nèi)容 android.permission.READ_SMS,讀取短信內(nèi)容 //振動 android.permission.VIBRATE,允許振動 //重啟設備 android.permission.REBOOT,允許程序重新啟動設備 //安裝應用程序 android.permission.INSTALL_PACKAGES,允許程序安裝應用 //修改聲音 android.permission.MODIFY_AUDIO_SETTINGS,修改聲音設置信息 //錄音 android.permission.RECORD_AUDIO,錄制聲音通過手機或耳機的麥克 //使用閃光燈 android.permission.FLASHLIGHT,允許訪問閃光燈 //訪問網(wǎng)絡 android.permission.INTERNET,訪問網(wǎng)絡連接,可能產(chǎn)生GPRS流量 //改變wifi狀態(tài) android.permission.CHANGE_WIFI_STATE,打開wifi,改變wifi狀態(tài) //獲取WiFi狀態(tài) android.permission.ACCESS_WIFI_STATE,獲取當前WiFi接入的狀態(tài)以及WLAN熱點的信息 //獲取網(wǎng)絡狀態(tài) android.permission.ACCESS_NETWORK_STATE,獲取網(wǎng)絡信息狀態(tài),如當前的網(wǎng)絡連接是否有效 //拍照權限 android.permission.CAMERA,允許訪問攝像頭進行拍照 //使用藍牙 android.permission.BLUETOOTH,允許程序連接配對過的藍牙設備 //電池狀態(tài) android.permission.BATTERY_STATS,允許應用程序獲取電池狀態(tài)的權限
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android系統(tǒng)添加Linux驅動
- Android實現(xiàn)EditText添加下劃線
- Android添加用戶組及自定義App權限的方法
- Android中多行文本末尾添加圖片排版問題的解決方法
- Android添加指紋解鎖功能的實現(xiàn)代碼
- Android實現(xiàn)添加商品到購物車動畫效果
- Android GridView仿微信添加多圖效果
- Android中recyclerView底部添加透明漸變效果
- Android GridView添加頭部問題的解決
- 詳解如何在Android Studio中添加RecyclerView-v7支持包
- Android百度地圖添加Marker失真問題的解決方案
- Android手機屏幕同步工具asm.jar
- Android中APK簽名工具之jarsigner和apksigner詳解
- 超實用的android網(wǎng)絡工具類
- Android編程實現(xiàn)將時間轉化成幾分鐘前、幾天前等形式的工具類
- Android系統(tǒng)添加自己寫的工具
相關文章
Android 創(chuàng)建與解析XML(四)——詳解Pull方式
本篇文章主要介紹了Android創(chuàng)建與解析XML(二)——詳解Pull方式,這里整理了詳細的代碼,有需要的小伙伴可以參考下。2016-11-11
Android M(6.x)使用OkHttp包解析和發(fā)送JSON請求的教程
Android 6.0采用的SPDY支持HTTP上GZIP壓縮的傳輸,這使得OkHttp包的功能能夠進一步被利用,本文我們來總結一下Android M(6.0)使用OkHttp包解析和發(fā)送JSON請求的教程2016-07-07
Andriod Service與Thread的區(qū)別介紹
我們要明確Service是運行在主線程的,不能有耗時操作,這樣,在Service中處理耗時操作的時候,我們依然需要使用線程來處理,既然在Service里也要創(chuàng)建一個子線程,那為什么不直接在Activity里創(chuàng)建呢,下面通過本文給大家介紹Andriod Service與Thread的區(qū)別,一起看看吧2017-04-04
Android Bitmap和Drawable相互轉換的簡單代碼
Android Bitmap和Drawable相互轉換的簡單代碼,需要的朋友可以參考一下2013-05-05

