简体   繁体   English

我该怎么做才能让应用程序在用户从自动启用位置权限返回后自动调用 getlocationpermission

[英]How do I make it so the app will automatically call getlocationpermission after the user returns from enabling location permission automatically

   public void statusCheck() {
    final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        Intent intent = new Intent(MainActivity.this, NewActivity.class);
        buildAlertMessageNoGps();
    }

    while(manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && i<2)
    {
        getLocationPermission();
        i++;

    }
}

This is my code.这是我的代码。 Right now if location permission is not enabled, there will be an alert dialog that will take the user to their settings to enable it.现在,如果未启用位置权限,将会出现一个警告对话框,将用户带到他们的设置以启用它。 However, when they return getlocationpermission() is not run so the app won't work.但是,当他们返回时, getlocationpermission()未运行,因此该应用程序将无法运行。 How do I make it so that the app will automatically call getlocationpermission() after the user returns from enabling location permission?如何使应用程序在用户启用位置权限返回后自动调用getlocationpermission() Why is my code not working, why will it not call getLocationpermission after user manager.isProviderEnabled(LocationManager.GPS_PROVIDER) is true.为什么我的代码不起作用,为什么在用户manager.isProviderEnabled(LocationManager.GPS_PROVIDER)为真后它不调用getLocationpermission

i think it need more time to connect GPS, try use boolean.我认为连接 GPS 需要更多时间,请尝试使用 boolean。

Exemple:例子:

while(!GpsWorking)
{
    getLocationPermission();
}

publick void  getLocationPermission()
{
//if gps working
GpsWorking = true;
}

in simple terms you will call the method until you get the location简单来说,您将调用该方法,直到获得位置

once the location is received, the while(!GpsWorking) will exit收到位置后, while(!GpsWorking)将退出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何做才能使此框中的圆真正自动移动? - How do I make it so the circle in this frame actually moves automatically? 如何使MongoDB自动调用generateIdIfAbsentFromDocument? - How do I make MongoDB call generateIdIfAbsentFromDocument automatically? 如何从 firebase 身份验证中删除用户,以便用户自动从应用程序中注销? - How to delete the user from firebase auth so the user will automatically logged out from the app? 我的应用未请求位置权限,权限被自动拒绝 - My app is not requesting for location permission and the permission is denied automatically 如何在我的 android 应用程序中根据请求自动授予 SYSTEM_ALERT_WINDOW 权限? - How do I grant SYSTEM_ALERT_WINDOW permission automatically on request, in my android App? 如何使 JList 与 netbeans Swing 应用程序中的窗口一起自动拉伸? - How do I make a JList automatically stretch with the window in a netbeans Swing app? 如何创建可以自动关闭的独立Camel应用程序? - How do I make a standalone Camel application that can automatically shutdown? 如何检查通话是由用户终止还是自动终止? - How to check if call was ended by the user or automatically? 在Eclipse中构建Java之后如何自动导出WAR? - How do I automatically export a WAR after Java build in Eclipse? 如何在构建时自动使Speedment重新生成代码 - How do I make Speedment regenerate code automatically on build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM