kvdroid / Kvdroid

Some Pyjnius tools for Kivy-Android developments.
MIT License
94 stars 24 forks source link

Priority not working on Android version 8 and above #54

Open Hypocrate-code opened 9 months ago

Hypocrate-code commented 9 months ago

Hey ! I resolved the previous issues i had, Now i get it working in some ways, but i need help for a few details :

1) Here is my code in python :

@mainthread 
def send_notification(content):
    print("notification about to be sent")
    create_notification(
        small_icon=get_resource("drawable").ic_launcher,
        channel_id="ch1",  # you must set this to any string value of your choice
        title="HypLoad",  # title of your notification
        text=f"{content}",  # notification content text
        ids=1,  # notification id, can be used to update certain notification
        channel_name=f"message",
        action_title1="action1",
        priority=NotificationCompat().PRIORITY_MIN
    )
    print("notification sent")

I use the decorator @mainthread to get it working, because notifications have to be sent with the main thread, otherwise i get all the problems i was talking about before (can't use create_notification because the function can't access some androidx and android values) Whereas, i want the notification to be sent when the app is left but still opened But if i launch them with the main thread, they only appear when i go back to the app, because the main thread is stopped when the app is left. So do you have any ideas on how i could proceed to have notifications sent when the app is active but not opened ?

2) When i use get_resource("drawable").ic_launcher (ic_launcher.png being my resource added as a drawable), the icon appears but is totally grey, instead of having its colors of origin.

3) NotificationCompat().PRIORITY_MIN works just as NotificationCompat().PRIORITY_LOW that works just as if no priority was set. How can i get it working (i don't want it to show up on the screen, but just to appear in the status bar)

IMPORTANT FACT : with android.api = 34, for me, create_notification was not creating any error but didn't do anything. Now that i have android.api = 32, notifications are sent but i still have issues mentionned above

Thanks for your time

Hypocrate-code commented 9 months ago

@kengoon

kengoon commented 9 months ago

@Hypocrate-code Using android API 34, you have to add the the POST_NOTIFICATION permission to your buildozer permission and also request for it too.

For the grey icon, that has nothing to do with kvdroid, watch this video to understand how to solve your issues

For the priority, it only works on Android version 7 below. Feature update would be added for android version 8 above

Hypocrate-code commented 9 months ago

Thanks for your answers ! I'll try it out asap, Did you understand the problem with threads/sending notification when the app is opened and left ? Do you need more context ?

kengoon commented 9 months ago

@Hypocrate-code use a service to send notifications, services run in the background. Don't ask me how to use service, go and figure that out on your own