如何检查GPS是否被禁用安卓
我有两个文件MainActivity.java和HomeFragment.java在MainActivity中调用HomeFragment的函数,该函数要求用户打开手机上的位置服务。问题是,即使用户已经打开了位置功能,该功能仍然被调用。有没有办法让我只有当位置功能关闭时,才能启动HomeFragment中的功能。
家庭碎屑.java
public static void displayPromptForEnablingGPS(
final Activity activity)
{
final AlertDialog.Builder builder =
new AlertDialog.Builder(activity);
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
final String message = "Enable either GPS or any other location"
+ " service to find current location. Click OK to go to"
+ " location services settings to let you do so.";
builder.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
activity.startActivity(new Intent(action));
d.dismiss();
}
});
builder.create().show();
}
主要活动.java
public void showMainView() {
HomeFragment.displayPromptForEnablingGPS(this);
}
谢谢:)