Skip to content

push notification for android? need permission ACTION_APP_NOTIFICATION_SETTINGS #2989

Description

@Heoder

I need android notification permission so pyler can show notifications but flet doesn't support pyjnius, what should I do?
my code
`from plyer import notification
import flet as ft
import os

def main(page: ft.Page):
page.title = "Notification Example"
page.vertical_alignment = ft.MainAxisAlignment.CENTER

def notify_click(e):
    # Check if we are on Android
    if os.name == 'posix':
        # Import the necessary Android classes
        from plyer.platforms.android import activity
        from jnius import autoclass

        # Check if we have the notification permission
        NotificationManager = autoclass('android.app.NotificationManager')
        if not NotificationManager.areNotificationsEnabled(activity):
            # If not, request it
            Intent = autoclass('android.content.Intent')
            Settings = autoclass('android.provider.Settings')
            intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
            intent.putExtra(Settings.EXTRA_APP_PACKAGE, activity.getPackageName())
            activity.startActivity(intent)
        else:
            # If we have the permission, show the notification
            notification.notify(
                title='Here is the title',
                message='Here is the message',
                app_icon=None,
                timeout=10,
            )
    else:
        # If we are not on Android, just show the notification
        notification.notify(
            title='Here is the title',
            message='Here is the message',
            app_icon=None,
            timeout=10,
        )
    page.update()

page.add(
    ft.Row(
        [
            ft.IconButton(ft.icons.NOTIFICATIONS, on_click=notify_click),
        ],
        alignment=ft.MainAxisAlignment.CENTER,
    )
)

ft.app(main,assets_dir="assets")
`

Building package executable... (2.1s)
Built serious_python:main.
Running package command
Creating asset directory: C:\Users\USER\AppData\Local\Temp\flet_flutter_build_ifzzBTMWlt\app
Copying Python app from E:\Coder\Python\test\test1 to C:\Users\USER\AppData\Local\Temp\serious_python_tempe907b2a4
Configured mobile platform with sitecustomize.py at C:\Users\USER\AppData\Local\Temp\serious_python_sitecustomizec340dc46\sitecustomize.py
Installing dependencies [flet-embed==0.21.1, plyer==2.1.0, pyjnius==1.6.1] with pip command to C:\Users\USER\AppData\Local\Temp\serious_python_tempe907b2a4_pypackages_
Extracting Python distributive from C:\Users\USER\AppData\Local\Temp\cpython-3.11.6+20231002-x86_64-pc-windows-msvc-shared-install_only.tar.gz to C:\Users\USER\AppData\Local\Temp\hostpython3.11_89ed782f
VERBOSE: C:\Users\USER\AppData\Local\Temp\hostpython3.11_89ed782f\python\python.exe -m pip install --isolated --upgrade --target C:\Users\USER\AppData\Local\Temp\serious_python_tempe907b2a4_pypackages_ flet-embed==0.21.1 plyer==2.1.0 pyjnius==1.6.1
VERBOSE: Collecting flet-embed==0.21.1
VERBOSE: Obtaining dependency information for flet-embed==0.21.1 from https://files.pythonhosted.org/packages/65/65/74df720408e5a85a57579a06e0f0bd2370e4a7ff218bc149b53b18f4dd43/flet_embed-0.21.1-py3-none-any.whl.metadataVERBOSE: Using cached flet_embed-0.21.1-py3-none-any.whl.metadata (1.0 kB)
VERBOSE: Collecting plyer==2.1.0
VERBOSE: Obtaining dependency information for plyer==2.1.0 from https://files.pythonhosted.org/packages/d3/89/a41c2643fc8eabeb84791acb9d0e4d139b1e4b53473cc4dae947b5fa33ed/plyer-2.1.0-py2.py3-none-any.whl.metadata
VERBOSE: Using cached plyer-2.1.0-py2.py3-none-any.whl.metadata (61 kB)
VERBOSE: Collecting pyjnius==1.6.1
VERBOSE: Downloading pyjnius-1.6.1.tar.gz (63 kB)
VERBOSE: ---------------------------------------- 63.4/63.4 kB 3.3 MB/s eta 0:00:00
VERBOSE:
VERBOSE: Installing build dependencies: started
VERBOSE: Installing build dependencies: finished with status 'done'
VERBOSE: Getting requirements to build wheel: started
VERBOSE: Getting requirements to build wheel: finished with status 'error'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions