在android中使用cordova重定向到位置设置

在android中使用cordova重定向到位置设置,android,cordova,gps,ionic-framework,cordova-plugins,Android,Cordova,Gps,Ionic Framework,Cordova Plugins,以下是我试图在cordova android应用程序中实现的要求 当用户进入主页时,检查gps是否启用 如果未启用,我想让用户打开位置设置 第一部分是用GPS探测器插件制作的,第二部分是用WebIntent插件实现的,但它并没有像我预期的那样工作 if(!gps){ //gps is disabled try to show the location setting using webintent plugin window.plugins.webintent.startAct

以下是我试图在cordova android应用程序中实现的要求

  • 当用户进入主页时,检查gps是否启用

  • 如果未启用,我想让用户打开位置设置

  • 第一部分是用GPS探测器插件制作的,第二部分是用WebIntent插件实现的,但它并没有像我预期的那样工作

    if(!gps){
         //gps is disabled try to show the location setting using webintent plugin
        window.plugins.webintent.startActivity(
            {
                action: window.plugins.webintent.ACTION_LOCATION_SOURCE_SETTINGS,
            },
            function() {},
            function() {
                alert('Failed to open URL via Android Intent.');
                console.log("Failed to open URL via Android Intent. URL: " + theFile.fullPath)
            }
        );              
    }
    

    我收到此错误
    无法通过Android Intent打开URL

    您可以使用。一旦安装,您可以通过JS将其称为:

    cordova.plugins.diagnostic.switchToLocationSettings();
    
    更新

    您可以使用直接从应用程序内请求高精度定位模式(即GPS)。这将显示本机确认对话框,如果用户同意,GPS将自动启用,要求用户手动更改设置:

    function onRequestSuccess(success){
        console.log("Successfully requested accuracy: "+success.message);
    }
    
    function onRequestFailure(error){
        console.error("Accuracy request failed: error code="+error.code+"; error message="+error.message);
        if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
            if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
                cordova.plugins.diagnostic.switchToLocationSettings();
            }
        }
    }
    
    cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
    

    帮帮我伙计们我也有同样的问题,但没有解决你用什么插件检查gps?请?我已经创建了自己的gps探测器插件,将在我的github@Root,你是怎么做到的?没关系!虽然它是一个phonegap插件,上一次提交是在10月13日,但它在Ionic 1.0中是开箱即用的。0@FernandoFabreti仅供参考,为了添加文档并将插件发布到npm和cordova注册中心,我最近分叉了该回购协议-分叉回购协议很棒!我注意到在我的Galaxy S4设备上,
    Diagnostic.prototype.isGpsEnabled
    总是返回
    true
    。你的医生说你的“相似”版本仅在启用高精度时返回
    true
    ,你改变了吗?我会看看你的代码,谢谢。我没有在我的fork中更改代码-只是根据代码注释添加了文档,所以可能是我的文档错了。