android_notify icon indicating copy to clipboard operation
android_notify copied to clipboard

White Blank Small Icon on Android 12

Open Nemesai38 opened this issue 2 months ago • 12 comments

Phone: SAMSUNG A02s
Android Version: Android 12

Image

The Notification top right icon doesnt pick the icon of the App

from kivy.lang import Builder
from kivy.utils import platform
from kivy.core.window import Window
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen


class MainScreen(MDScreen):
    def send_notification(self):
        try:
            from android_notify import Notification
            from android_notify import NotificationHandler

            NotificationHandler.asks_permission()

            Notification.createChannel(
                id='shake',
                name='Shake Passage',
                vibrate=True
            )

            notification = Notification(
                channel_id='shake',
                title="Hello from KivyMD!!",
                message="your custom image notification has arrived.",
                logs=True,
            )

            notification.setBigPicture("./assets/imgs/red-cmddb-icon.png")
            notification.send()
            print("Notification sent successfully!!")
        except ImportError:
            print("android_notify not found. Please install it.")
            self.ids.status_label.text = "Notification module not available"
        except Exception as e:
            print(f"Error sending notification: {e}")
            self.ids.status_label.text = f"Error: {str(e)}...."

    def on_enter(self, *args):
        self.ids.status_label.text = "Ready to send notification"


KV = """
<MainScreen>:
    name: "home_screen"
    MDBoxLayout:
        orientation: 'vertical'
        padding: dp(20)
        spacing: dp(20)
        
        MDLabel:
            id: status_label
            text: "Press the button to send a notification with your image"
            halign: 'center'
            font_style: 'H5'
            size_hint_y: None
            height: self.texture_size[1] + dp(20)
        
        Widget:
            size_hint_y: 1
            
        MDRectangleFlatButton:
            text: "Press Me"
            font_size: sp(24)
            size_hint: None, None
            size: dp(200), dp(60)
            pos_hint: {'center_x': 0.5}
            on_release: root.send_notification()
            
        Widget:
            size_hint_y: 1
            
        MDLabel:
            text: "Image should be in: assets/imgs"
            halign: 'center'
            font_style: 'Caption'
            theme_text_color: 'Secondary'
            size_hint_y: None
            height: self.texture_size[1] + dp(10)
"""


class MyNotificationApp(MDApp):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = None

    def build(self):
        if platform == "android":
            Window.maximize()
        else:
            Window.size = (400, 600)
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"
        self.screen = Builder.load_string(KV)
        return MainScreen()

    def on_resume(self):
        return self.screen


if __name__ == '__main__':
    MyNotificationApp().run()

Image: Image

Collapsed Notification:

Image

Nemesai38 avatar Sep 13 '26 18:09 Nemesai38

thanks for all the details, they'll be really useful. I'm going to use them to run some tests to try replicate the issue, I'll get back to you once i have a definite results.

Fector101 avatar Sep 13 '26 20:09 Fector101

Nice work @Fector101! How can I know the exact upgrades from android-notify==1.61.7 to android-notify==1.61.9?

Nemesai38 avatar Sep 24 '26 10:09 Nemesai38

Each version 1.58 to 1.61, has it's stable release. After that I'm suppose to write the documentation covering things that changed between each stable version here

1.61.8

  • intial release for music notification feature
  • removes passing in channel id to Notification$Builder for android versions lower than 8
  • removes notification permission check for android versions lower than 7
  • Notification.getChannels return readable data

1.61.9

  • patches to music notifcation

The next release will be v1.62 Anything after 1.61.8 tagged with 1.61.* is an emergency patch

Version Stable release
1.58 1.58
1.59 1.59.4
1.60 1.60.10
1.61 1.61.8

Fector101 avatar Sep 24 '26 12:09 Fector101

I've had no luck replicating your issue yet, pls send a screenshot of what other apps notification looks like on your phone

snippet

p="/storage/emulated/0/Download/test.png"
notification = Notification(
    channel_id='shake',
    title="Hello from KivyMD!!",
    message="your custom image notification has arrived.",
    logs=True,
)

notification.setBigPicture(p)
notification.setSmallIcon(p)
notification.send()

I've tested on these devices

  • Redmi 13C: android 15
  • samsung galaxy A31 : android 12 - One UI 4.1
  • samsung galaxy A20 : android 11
  • tecno pova 2: android 12

screenshots

  • Redmi 13C: android 15
Image
  • samsung galaxy A31 : android 12 - One UI 4.1
Image

Fector101 avatar Sep 24 '26 13:09 Fector101

ok i see where the issue was, I use buildozer and this was the icon section in the buildozer.spec file:

# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png

# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png

Because by default the KivyMD logo shows for the app icon and splash screen so i believe thats why it didn't show up for the notification. I used my custom icon and it worked for the notification.

Nemesai38 avatar Sep 25 '26 06:09 Nemesai38

You're absolutely right i just recreated the behavior, can't believe i missed it. kivy's default icon is not a real PNG I'm gonna push a patch

Image

Fector101 avatar Sep 25 '26 23:09 Fector101

hey @Nemesai38 , try using fix/default-kivy-icon-not-png branch in your requirements to test if it fixes the issue

Also run android-notify prune in your project dir, to remove old version

requirements = python3, kivy, https://github.com/Fector101/android_notify/archive/fix/default-kivy-icon-not-png.zip

Fector101 avatar Sep 26 '26 02:09 Fector101

cool

requirements = python3, kivy, https://github.com/Fector101/android_notify/archive/fix/default-kivy-icon-not-png.zip

worked ok.

Image

Nemesai38 avatar Sep 26 '26 15:09 Nemesai38

Hey @Nemesai38 thanks for reproducing it and for confirming the fix on your device.

Your call on it was right: with icon.filename commented out, the app was falling back to Kivy's default icon. What I didn't know until I went digging is why Kivy's default icon isn't a real PNG, so it can't be used as a small icon at all. That's the part I've now fixed, by bundling a proper PNG fallback.

It's released as 1.61.10:

requirements = python3, kivy, android-notify

Run android-notify prune in your project dir first, so the branch build doesn't linger in .buildozer.

Heads up: that .../archive/fix/default-kivy-icon-not-png.zip URL stops resolving once the branch is deleted, and the next build will fail on it, Let me know once you've switched and I'll delete the branch.

Fector101 avatar Sep 26 '26 17:09 Fector101

@Fector101 Nice one. You can go ahead and delete the branch now.

Nemesai38 avatar Sep 26 '26 19:09 Nemesai38

Hey @Fector101, using my exact same code as above, i wanted to make it send timely notifications so from the documentation this is my service.py to test this:

from android_notify import Notification
from android_notify.config import get_python_service
from android_notify.internal.java_classes import BuildVersion, autoclass
import time

service = get_python_service()

foreground_type = 0
if BuildVersion.SDK_INT >= 34:
    # Required type on Android 14+ (SDK 34), 0 on older devices
    ServiceInfo = autoclass("android.content.pm.ServiceInfo")
    foreground_type = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE

Notification.createChannel(
    id="foreground_channel",
    name="Foreground Service",
    description="For Setting timely Notifications",
)

notification = Notification(
    channel_id="foreground_channel",
    title="Starting foreground service...",
    name="from service",
)

builder = notification.fill_args()  # fill args into the builder (nothing posted yet)
service.startForeground(notification.id, builder.build(), foreground_type)
service.setAutoRestartService(True)

# Your service logic goes here
# Example: while True: do_something()

while True:
    print("Foreground Service started....!!!!")
    time.sleep(15)

In buildozer.spec:

services = ForegroundService:./service.py:foreground
.
.
.
android.permissions = VIBRATE, POST_NOTIFICATIONS, FOREGROUND_SERVICE

My main.py remaining the same, no changes. But on running the service doesn't start. Is there anything i'm to still include?

Nemesai38 avatar Sep 27 '26 06:09 Nemesai38

Hey @Nemesai38 You have to tell your service to begin

# ./main.py
from android import mActivity
from jnius import autoclass

context = mActivity.getApplicationContext()
service_name = "Foregroundservice"
service = autoclass(context.getPackageName() + '.Service' + service_name.capitalize())
service.start(mActivity, "")

And don't forget to add it's permission, since you're using ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE add FOREGROUND_SERVICE_SPECIAL_USE in android.permissions

services = Foregroundservice:./service.py:foreground:foregroundServiceType=specialUse
android.permissions = VIBRATE, FOREGROUND_SERVICE, POST_NOTIFICATIONS, FOREGROUND_SERVICE_SPECIAL_USE

Also when you use ForegroundService as your service name kivy creates Foregroundservice with s in lowercase, So always capitalized your service name to be safe.

BONUS:

import time

fmt = lambda s: f"{int(s//3600)}h {int((s%3600)//60)}m {int(s%60)}s"
start = time.time()
END_TIME = 6 * 3600
while True:
    elapsed = time.time() - start
    if elapsed >= END_TIME:
        notification.updateTitle(f"Total runtime {fmt(elapsed)}")
        break
    notification.updateTitle(f"Running for {fmt(elapsed)}")
    time.sleep(1)

To see your service logs

adb logcat | grep -E "python|Foregroundservice"

Fector101 avatar Sep 27 '26 18:09 Fector101