使用cordova在Android中重定向到位置设置 [英] Redirect to location settings using cordova in android

查看:2133
本文介绍了使用cordova在Android中重定向到位置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我想在我的cordova Android应用程序中实现的要求

Here is the requirements what i am trying to implement in my cordova android application


  1. 当用户输入主页检查

  1. When user enters the home page check to see if the gps is enabled or not.

如果未启用,我想指向用户打开位置设置。

If not enabled i want to point the user to turn on the location settings.

第一部分使用GPS检测器插件很容易,第二部分是使用web意图插件实现的。但它不能像我预期的那样工作。 / p>

first part is made easily with GPS detector plugin and second part is implemented using the web intent plugin.But its not working as i expected.

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)
        }
    );              
}

我收到此错误

I am getting this error Failed to open URL via Android Intent.

推荐答案

您可以使用 cordova-diagnostic-plugin 。一旦安装,你通过JS调用它像:

You can achieve this using the cordova-diagnostic-plugin. Once installed, you call it via JS something like:

cordova.plugins.diagnostic.switchToLocationSettings();

UPDATE

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

You can use cordova-plugin-request-location-accuracy to request high accuracy location mode (i.e. GPS) directly from within the app. This will show a native confirm dialog and if user agrees, GPS will be enabled automatically with requiring user to manually change settings:

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);

这篇关于使用cordova在Android中重定向到位置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆