Android ใใใคในใงไฝ็ฝฎๆ
ๅ ฑใๆๅนใซใชใฃใฆใใใใฉใใใ็ขบ่ชใใๆนๆณใซใคใใฆ่ฉณ็ดฐใช่จไบใๆธใใซใฏใJava ใใญใฐใฉใใณใฐใจใใพใใพใช Android ใฉใคใใฉใชใฎไฝฟ็จใซใคใใฆใฎๅๅใช็่งฃใๅฟ
่ฆใซใชใๅ ดๅใใใใพใใใใใงใใใใซใคใใฆ่ฉณใใ่ฆใฆใใใพใใใใ
็พไปฃใฎใขใใคใซ ใขใใชใฑใผใทใงใณ็ฐๅขใงใฏใใฆใผใถใผใฎๅฐ็็ไฝ็ฝฎใซๅบใฅใใฆใใผใฝใใฉใคใบใใใใจใฏในใใชใจใณในใๆไพใใใใใซใใฆใผใถใผใฎไฝ็ฝฎใซใขใฏใปในใใใใจใ้่ฆใซใชใฃใฆใใพใใใใฎๆฉ่ฝใฏใAndroid ใๆญ่ผใใใใใคในใง่ฑๅฏใซๅฉ็จใงใใพใใใใ ใใไฝ็ฝฎๆ
ๅ ฑใๆๅนใใฉใใใๅคๆญใใใใจใ้่ฆใชๅด้ขใงใใ
public boolean isLocationEnabled(Context context) {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
} else {
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}
ใณใผใใ็่งฃใใ
ไธ่จใฎใณใผใใฏใAndroid ใใใคในใงไฝ็ฝฎๆ
ๅ ฑใตใผใในใๆๅนใซใชใฃใฆใใใใฉใใใ XNUMX ใคใฎไธป่ฆใชๆ้ ใงใใงใใฏใใพใใ
โ ใใใคในใฎใใผใธใงใณใ KitKat ไปฅ้ใฎๅ ดๅใไฝ็ฝฎๆ
ๅ ฑใขใผใใฎ่จญๅฎใๅๅพใใใใจใใใใใใไฝ็ฝฎๆ
ๅ ฑใขใผใ ใชใใไปฅๅคใงใใใใฉใใใๆค่จผใใพใใใใใงใใใฐใใใฎไฝ็ฝฎๆ
ๅ ฑใๆๅนใงใใใใจใ็ขบ่ชใใใพใใ
โ KitKat ใใใๅคใใใผใธใงใณใงๅฎ่กใใใฆใใใใใคในใฎๅ ดๅใ่จฑๅฏใใใไฝ็ฝฎใใญใใคใใผใฎใชในใใๅๅพใใใใใๅฎๅ
จใซ็ฉบใงใใใใฉใใใ็ขบ่ชใใพใใใชในใใ็ฉบใงใชใๅ ดๅใฏใไฝ็ฝฎๆ
ๅ ฑใๆๅนใงใใใใจใ็ขบ่ชใใใพใใ
ใใพใใพใชใฉใคใใฉใชใจๆฉ่ฝใฎๅฝนๅฒ
ใใฎใณใผใใงใฏใไธปใซ Android Developer's Kit ใฎใใใคใใฎ็นๅฎใฎ้ขๆฐใจใฉใคใใฉใชใไฝฟ็จใใฆใใพใใ
- ใใซใ.VERSION.SDK_INT: ใใใฏใใใใคในไธใง็พๅจๅฎ่กใใใฆใใใใฉโโใใใใฉใผใ ใฎ SDK ใใผใธใงใณใไฟๆใใใใฃใผใซใใงใใ
- ่จญๅฎ.ใปใญใฅใข: ใใใฏใใฐใญใผใใซใงๅฎๅ
จใชใทในใใ ่จญๅฎใไธปใซใฆใผใถใผใฎใใฉใคใใทใผใซๅฝฑ้ฟใไธใใใทในใใ ่จญๅฎใธใฎใขใฏใปในใ็ฎก็ใใใฏใฉในใงใใ
- ่จญๅฎ.Secure.getInt: ใใฎใกใฝใใใฏใๆๅฎใใใๅๅใฎๅฎๅ
จใชๆดๆฐ่จญๅฎๅคใ่ฟใใพใใ
- ่จญๅฎ.ใปใญใฅใข.LOCATION_MODE: ใใใฏใ็พๅจใฎไฝ็ฝฎใขใผใ่จญๅฎใๅๅพใใใใใซไฝฟ็จใใใพใใ
- ่จญๅฎ.Secure.LOCATION_PROVIDERS_ALLOWED: ่จฑๅฏใใใไฝ็ฝฎๆ
ๅ ฑใใญใใคใใผใฎใชในใใๅๅพใใพใใ
็ถใใ่ชญใ