如何在Android或iOS中使用Phonegap重定向到GPS设置窗口以打开或关闭GPS

Abd*_*DDN 7 android ios phonegap-plugins cordova

我想在Phonegap中实现像Native android这样的功能,当用户想要通过按钮点击启用GPS时,它将被重定向到android或IOS的设置部分,以便用户可以在GPS的按钮上.

因为我们无法直接打开或关闭设备上的GPS,我们只能将用户重定向到设置,因此如何将其重定向到Android和iOS的Phonegap设置.

我想在Phonegap中实现以下功能.

/**
 * Function to check if best network provider
 * @return boolean
 * */
public boolean canGetLocation() {
    return this.canGetLocation;
}

/**
 * Function to show settings alert dialog
 * */
public void showSettingsAlert(){
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

    // Setting Dialog Title
    alertDialog.setTitle("GPS is settings");

    // Setting Dialog Message
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

    // Setting Icon to Dialog
    //alertDialog.setIcon(R.drawable.delete);

    // On pressing Settings button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
        }
    });

    // on pressing cancel button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        dialog.cancel();
        }
    });

    // Showing Alert Message
    alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)

Ven*_*h S 7

startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
Run Code Online (Sandbox Code Playgroud)

尝试这个意图的朋友它带你到位置设置...

  • 我正在寻求"使用phonegap",我的朋友. (3认同)