![](/img/trans.png)
[英]How to redirect the app to location sensor settings in android using delphi
[英]Redirect to location settings using cordova in android
這是我想要在我的cordova android應用程序中實現的要求
當用戶進入主頁時,檢查是否啟用了gps。
如果未啟用,我想指向用戶打開位置設置。
第一部分是使用GPS探測器插件輕松制作的,第二部分是使用網絡意圖插件實現的。但它沒有像我預期的那樣工作。
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)
}
);
}
我收到此錯誤Failed to open URL via Android Intent
。
您可以使用cordova-diagnostic-plugin實現此目的。 安裝完成后,您可以通過JS調用它:
cordova.plugins.diagnostic.switchToLocationSettings();
UPDATE
您可以使用cordova-plugin-request-location-accuracy直接從應用程序內請求高精度定位模式(即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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.