[英]to check location service enable or not in android device
很抱歉問這個問題,但我不是 android 應用程序的開發人員。 我想問一下是否可以對自定義地理定位 android 應用程序進行編碼,以便當用戶啟動應用程序並檢測到設備的位置服務已關閉時,它將顯示為提示,或者應用程序在位置服務之前不會繼續進行是否由用戶手動開啟?
我們正在使用移動設備管理 (mdm) 來管理 android 移動設備,但 mdm 沒有強制執行位置服務設置的能力。
自定義地理位置 android 應用程序需要啟用位置服務才能正常工作。
您可以檢查 GPS 是否啟用,如果未啟用則顯示消息
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//here do what you want when the GPS service is enabled
Toast.makeText(MainActivity.this, "is enable", Toast.LENGTH_SHORT).show();
} else {
MaterialAlertDialogBuilder locationDialog = new MaterialAlertDialogBuilder(MainActivity.this);
locationDialog.setTitle("Attention");
locationDialog.setMessage("Location settings must be enabled from the settings to use the application");
locationDialog.setCancelable(false);
locationDialog.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
locationDialog.create().show();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.