flet icon indicating copy to clipboard operation
flet copied to clipboard

geolocator not working on Android devices.

Open Gorkor227 opened this issue 2 years ago • 5 comments

Duplicate Check

  • [X] I have searched the opened issues and there are no duplicates

Describe the bug

Use this demo: https://flet.dev/docs/controls/geolocator/

                "request_permission",  No error, no effect

                "get_permission_status", No error, no effect

                "get_current_position", No error, no effect

                "get_last_known_position", No error, no effect

                "is_location_service_enabled", No error, no effect

                "open_location_settings", ok, but can't find my app

                "open_app_settings", ok, but can't find the location permission

I can open the location permission configuration page, but I can't find my app on the page. I open the permission page by long pressing the app, and I can't find the location permission among all the permissions. And it shows that no permissions are granted. I don't know how to deal with such a problem. I tested win10 and everything was normal. But there is a problem on Android. My device is Android 14.

Code

copy from demo.

import flet as ft

async def main(page: ft.Page): page.window.always_on_top = True page.on_error = lambda e: print(f"Page Error: {e.data}") page.scroll = ft.ScrollMode.ADAPTIVE page.appbar = ft.AppBar(title=ft.Text("Geolocator Tests")) gl = ft.Geolocator() page.overlay.append(gl)

settings_dlg = lambda handler: ft.AlertDialog(
    adaptive=True,
    title=ft.Text("Opening Location Settings..."),
    content=ft.Text(
        "You are about to be redirected to the location/app settings. "
        "Please locate this app and grant it location permissions."
    ),
    actions=[
        ft.TextButton(
            text="OK",
            on_click=handler,
        ),
    ],
    actions_alignment=ft.MainAxisAlignment.CENTER,
)

def handle_permission_request(e):
    page.add(ft.Text(f"request_permission: {gl.request_permission()}"))

def handle_get_permission_status(e):
    page.add(ft.Text(f"get_permission_status: {gl.get_permission_status()}"))

def handle_get_current_position(e):
    p = gl.get_current_position()
    page.add(ft.Text(f"get_current_position: ({p.latitude}, {p.longitude})"))

def handle_get_last_known_position(e):
    p = gl.get_last_known_position()
    page.add(ft.Text(f"get_last_known_position: ({p.latitude}, {p.longitude})"))

def handle_location_service_enabled(e):
    page.add(
        ft.Text(f"is_location_service_enabled: {gl.is_location_service_enabled()}")
    )

def handle_open_location_settings(e):
    page.close_dialog()
    page.add(ft.Text(f"open_location_settings: {gl.open_location_settings()}"))

def handle_open_app_settings(e):
    page.close_dialog()
    page.add(ft.Text(f"open_app_settings: {gl.open_app_settings()}"))

page.add(
    ft.Row(
        [
            ft.OutlinedButton(
                "request_permission",
                on_click=handle_permission_request,
            ),
            ft.OutlinedButton(
                "get_permission_status",
                on_click=handle_get_permission_status,
            ),
            ft.OutlinedButton(
                "get_current_position",
                on_click=handle_get_current_position,
            ),
            ft.OutlinedButton(
                "get_last_known_position",
                visible=False if page.web else True,
                on_click=handle_get_last_known_position,
            ),
            ft.OutlinedButton(
                "is_location_service_enabled",
                on_click=handle_location_service_enabled,
            ),
            ft.OutlinedButton(
                "open_location_settings",
                visible=False if page.web else True,
                on_click=lambda e: page.show_dialog(
                    settings_dlg(handle_open_location_settings)
                ),
            ),
            ft.OutlinedButton(
                "open_app_settings",
                visible=False if page.web else True,
                on_click=lambda e: page.show_dialog(
                    settings_dlg(handle_open_app_settings)
                ),
            ),
        ],
        wrap=True,
    )
)

ft.app(main)

To reproduce

https://flet.dev/docs/controls/geolocator flet build apk --include-packages flet_geolocator

device: android 14

Expected behavior

No response

Screenshots

No response

Operating System

Windows

Operating system details

Microsoft Windows 10 professional

Flet version

0.23.2

Regression

No, it isn't

Suggestions

It may be a permission protection issue.I am actively looking for ways.

Additional details

No response

Gorkor227 avatar Jun 30 '24 14:06 Gorkor227

I also face the same problem. In the whitelist, location does not appear. And when I look for the app in the whitelist, it doesn't appear either.

nascin avatar Jun 30 '24 16:06 nascin

I updated the 0.23.2 build-template. Could you guys try rebuilding your apps and provide feedback?

ndonkoHenri avatar Jul 01 '24 12:07 ndonkoHenri

我更新了0.23.2构建模板。 你们能尝试重建应用程序并提供反馈吗? Great, everything works fine. However, get_current_position has a delay of about 5 seconds, which I'm not sure is normal behavior.

Gorkor227 avatar Jul 01 '24 16:07 Gorkor227

Two things that might help:

  • reduce the accuracy level. I guess, smaller accurate levels should require shorter time comparatively.
  • before getting the current position, first get the "last known position" (it should be faster to grab), then update your UI when you receive the current position

ndonkoHenri avatar Jul 01 '24 19:07 ndonkoHenri

Hello I don't want to use async, and when I use gl.get_current_position, I get an error after the timeout

HappyCoder256 avatar Jan 20 '25 22:01 HappyCoder256