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

push notification for android? need permission ACTION_APP_NOTIFICATION_SETTINGS #2989

Closed
akunzz opened this issue Mar 13, 2024 · 2 comments
Closed
Labels

Comments

@akunzz
Copy link

akunzz commented Mar 13, 2024

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'

@misl6 misl6 added the support label Mar 13, 2024
Copy link

👋 @akunzz,
Sorry to hear you are having difficulties with Kivy's python-for-android; Kivy unites a number of different technologies, so building apps can be temperamental.
We try to use GitHub issues only to track work for developers to do to fix bugs and add new features to python-for-android.
However, this issue appears to be a support request. Please use our support channels to get help with the project.
If you're having trouble installing python-for-android, please see our quickstart guide.
If you're having trouble using python-for-android, please see our troubleshooting guide and FAQ.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2024
@akunzz
Copy link
Author

akunzz commented Mar 14, 2024

thanks so much!

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

No branches or pull requests

2 participants