ๆฐๅๆๅ
ณๅฆไฝๆฃๆฅ 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 ่ฎพๅคไธๅฏ็จ๏ผ
โ ๅฆๆ่ฎพๅค็ๆฌไธบ KitKat ๆๆด้ซ็ๆฌ๏ผๅฎไผๅฐ่ฏ่ทๅไฝ็ฝฎๆจกๅผ่ฎพ็ฝฎๅนถ้ช่ฏๅ
ถๆฏๅฆไธบโไฝ็ฝฎๆจกๅผๅ
ณ้ญโไปฅๅค็่ฎพ็ฝฎใๅฆๆๆฏ๏ผๅ็กฎ่ฎค่ฏฅไฝ็ฝฎๅทฒๅฏ็จใ
โ ๅฏนไบ่ฟ่กๆฉไบ KitKat ็ๆฌ็่ฎพๅค๏ผๅฎไผ่ทๅๅ
่ฎธ็ไฝ็ฝฎๆไพๅๅ่กจๅนถๆฃๆฅๅฎๆฏๅฆๅฎๅ
จไธบ็ฉบใๅฆๆๅ่กจไธไธบ็ฉบ๏ผๅ็กฎ่ฎค่ฏฅไฝ็ฝฎๅทฒๅฏ็จใ
ไธๅๅพไนฆ้ฆ็ไฝ็จๅ่่ฝ
ๅจๆญคไปฃ็ ไธญ๏ผๆไปฌไฝฟ็จไบไธไบ็นๅฎ็ๅฝๆฐๅๅบ๏ผไธป่ฆๆฅ่ช Android ๅผๅไบบๅๅทฅๅ
ทๅ
๏ผ
- ๆๅปบ.VERSION.SDK_INT๏ผ ่ฏฅๅญๆฎตไฟๅญ่ฎพๅคไธๅฝๅ่ฟ่ก็ๅนณๅฐ็ SDK ็ๆฌใ
- ่ฎพ็ฝฎ.ๅฎๅ
จ๏ผ ่ฏฅ็ฑป็ฎก็ๅฏนๅ
จๅฑๅฎๅ
จ็ณป็ป่ฎพ็ฝฎ็่ฎฟ้ฎ๏ผไธป่ฆๆฏๅฝฑๅ็จๆท้็ง็็ณป็ป่ฎพ็ฝฎใ
- ่ฎพ็ฝฎ.Secure.getInt๏ผ ๆญคๆนๆณ่ฟๅ็ปๅฎๅ็งฐ็ๅฎๅ
จๆดๆฐ่ฎพ็ฝฎๅผใ
- ่ฎพ็ฝฎ.ๅฎๅ
จ.LOCATION_MODE๏ผ ่ฟ็จไบ่ทๅๅฝๅ็ๅฎไฝๆจกๅผ่ฎพ็ฝฎใ
- Settings.Secure.LOCATION_PROVIDERS_ALLOWED๏ผ ่ทๅๅ
่ฎธ็ไฝ็ฝฎๆไพๅ็ๅ่กจใ
้
่ฏปๆดๅค