如何打开GPS设置安卓设备?[已关闭]

2022-09-01 19:56:20

我正在制作GPS Android应用程序(带有Android的空气),我想要的是如果GPS关闭,我想在设备上打开GPS设置或打开GPS,但我不知道如何。我想在AS3中执行此操作或在Java中打开Android设置。感谢您的帮助!


答案 1

您只需使用此操作启动活动:

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

我在对话框中使用它:

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 = "Do you want open GPS setting?";

        builder.setMessage(message)
            .setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int id) {
                        activity.startActivity(new Intent(action));
                        d.dismiss();
                    }
            })
            .setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int id) {
                        d.cancel();
                    }
            });
        builder.create().show();
    }

答案 2
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);

推荐