Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geolocator not working on Android 11 #4534

Open
1 task done
SoyDaniel27 opened this issue Dec 10, 2024 · 0 comments
Open
1 task done

Geolocator not working on Android 11 #4534

SoyDaniel27 opened this issue Dec 10, 2024 · 0 comments

Comments

@SoyDaniel27
Copy link

Duplicate Check

Describe the bug

Use the following example: 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

Code sample

import flet as ft

async def main(page: ft.Page):
page.scroll = ft.ScrollMode.ADAPTIVE
page.appbar = ft.AppBar(title=ft.Text("Geolocator Tests"))

def handle_position_change(e):
    page.add(ft.Text(f"New position: {e.latitude} {e.longitude}"))

gl = ft.Geolocator(
    location_settings=ft.GeolocatorSettings(
        accuracy=ft.GeolocatorPositionAccuracy.LOW
    ),
    on_position_change=handle_position_change,
    on_error=lambda e: page.add(ft.Text(f"Error: {e.data}")),
)
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="Take me there", on_click=handler)],
    actions_alignment=ft.MainAxisAlignment.CENTER,
)

async def handle_permission_request(e):
    p = await gl.request_permission_async(wait_timeout=60)
    page.add(ft.Text(f"request_permission: {p}"))

async def handle_get_permission_status(e):
    p = await gl.get_permission_status_async()
    page.add(ft.Text(f"get_permission_status: {p}"))

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

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

async def handle_location_service_enabled(e):
    p = await gl.is_location_service_enabled_async()
    page.add(ft.Text(f"is_location_service_enabled: {p}"))

async def handle_open_location_settings(e):
    p = await gl.open_location_settings_async()
    page.close(location_settings_dlg)
    page.add(ft.Text(f"open_location_settings: {p}"))

async def handle_open_app_settings(e):
    p = await gl.open_app_settings_async()
    page.close(app_settings_dlg)
    page.add(ft.Text(f"open_app_settings: {p}"))

location_settings_dlg = settings_dlg(handle_open_location_settings)
app_settings_dlg = settings_dlg(handle_open_app_settings)

page.add(
    ft.Row(
        wrap=True,
        controls=[
            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.open(location_settings_dlg),
            ),
            ft.OutlinedButton(
                "Open App Settings",
                visible=False if page.web else True,
                on_click=lambda e: page.open(app_settings_dlg),
            ),
        ],
    )
)

ft.app(main)

To reproduce

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

device: android 11

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

Windows 10 Home

Flet version

0.25.0

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant