gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:30:47 26 4
gpt4 key购买 nike

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

因为我们无法以编程方式直接打开或关闭设备上的 GPS,我们只能将用户重定向到设置,那么如何在 Phonegap for Android 和 iOS 中将其重定向到设置。

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

最佳答案

startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));

试试这个 intent friend ,它会带你到位置设置...

关于android - 如何使用 Phonegap 重定向到 Android 或 iOS 中的 GPS 设置窗口以打开或关闭 GPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14620140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com