編輯:Android編程入門
WIFI
獲取WIFI狀態
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if(wifiManager != null){
int wifiState = wifiManager.getWifiState();
}
附:Wifi狀態有以下幾種:(括號內為所對應的的int值)
1. wifiManager.WIFI_STATE_DISABLED (1)
2. wifiManager..WIFI_STATE_ENABLED (3)
3. wifiManager..WIFI_STATE_DISABLING (0)
4 wifiManager..WIFI_STATE_ENABLING (2)
設置wifi狀態
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if(wifiManager == null){
return;
}
int wifiApState = wifiManager.getWifiApState(); //獲取wifi AP狀態
if((boolean值 && wifiApState == wifiManager.WIFI_AP_STATE_ENABLING || wifiApState == wifiManager.WIFI_AP_STATE_ENABLED){
wifiManager.setWifiApEnabled(null,false);
}
wifiManager.setWifiEnabled(boolean值);
倆處boolean值應相同
Bluetooth
藍牙有待後續補充
GPS
獲取GPS狀態
ContentResolver resolver = context.ContextResolver();
Boolean on = Settings.Secure.isLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER);
true為開啟狀態
設置GPS狀態:
Settings..Secure.setLocationProviderEnabled(resolver,LocationManager.GPS_PROVIDER,boolean值);
true為開啟狀態
SYNC(同步)
獲取當前系統同步狀態
ContentResolver resolver = context.ContextResolver();
Boolean on = resolver.getMasterSyncAutomatically();
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
設置同步
ContentResolver.setMasterSyncAutomatically(boolean值);
AirplaneMode(飛行模式)
獲取系統當前飛行模式狀態
ContentResolver resolver = context.ContextResolver();
boolean on = Settings.System.getInt(context.getContextResolver(),Settings.System.AIRPLANE_MODE_ON,0) == 1 ? true : false;
設置飛行模式:
Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,boolean值 ? 1 : 0);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state",boolean值);
context.sendBroadcast(intent);
倆個boolean值應該一致;
自動旋轉屏幕
獲取系統當前自動旋屏設置
ContentResolver resolver = context.ContextResolver();
boolean on = Settings.System.getInt(context.getContResolver(),Settings.System.ACCELEROMETER_ROTATION) ==1 ? true : false;
設置自動旋屏
ContentResolver resolver = context.ContextResolver();
Uri uri = Settings.System.getUriFor("accelerometer_rotation");
Settings.System.putInt(resolver,"accelerometer_rotation",boolean值 ? 1 :0);
resolver.notifyChange(uri,null);
靜音模式
獲取靜音模式
public int getMuteMode(Context context){
AudioManager audioManager = (AudioManager)context.getSystmService(Context.AUDIO_SERVICE);
if(audioManager.getRingerMode == AudioManager.RINGER_MODE_SILENT){ //靜音
return 0;
}else if(audioManager.getRingerMode == AudioManager.RINGER_MODE_VIBRATE){//振動
return 1;
} elsse {
retrn 2;
}
}
設置靜音模式
public void setMute(Context context){
AudioManager audioManager = (AudioManager)context.getSystmService(Context.AUDIO_SERVICE);
switch(getMuteMode(context){
case 0:
audioManager.stRingerMode(AudioManager.RINGER_MODE_VIBRATE); //振動模式
break;
case 1:
audioManager.stRingerMode(AudioManager.RINGER_MODE_NORMAL); //正常模式
break;
case 2:
audioManager.stRingerMode(AudioManager.RINGER_MODE_SILENT); //靜音模式
break;
default:
audioManager.stRingerMode(AudioManager.RINGER_MODE_NORMAL); //正常模式
}
}
鎖屏
PowerManager pm = (PowerManager)context.getSystemService(context.POWER_SERVICE);
pm.goToSleep(SystemClock.uptimeMillis());
Android項目的目錄結構: 資源文件夾:清單配置文件:Android的四大組件在使用前全部需要在清單文件中配置<?xml version
在Android5.0往後的平台上,你想通過單純的調用File.delete()或著ContentResolver.delete()來刪除Sdcard上的文件會刪除失敗。
一,簡述線程池:線程池是如何工作的:一系列任務出現後,根據自己的線程池安排任務進行。如圖: 線程池的好處:重用線程池中的線程,避免因為線程的創建和銷毀所帶來的性能開銷。能
1、android:clipToPadding意思是控件的繪制區域是否在padding裡面。默認為true。如果你設置了此屬性值為false,就能實現一個在布局上事半功陪