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常用許可權
//寫入外部存儲 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,允許應用程式獲取電池狀態的許可權