我想在 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();
}