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

Notification for android not working [ Drawable.icon ] #647

Closed
kyudorimj opened this issue Sep 21, 2021 · 14 comments
Closed

Notification for android not working [ Drawable.icon ] #647

kyudorimj opened this issue Sep 21, 2021 · 14 comments

Comments

@kyudorimj
Copy link
Contributor

kyudorimj commented Sep 21, 2021

I'm building an android app in buildozer with plyer. It seems that the notification don't work.
My simple code for notification using plyer:

notification.notify(title='WARNING!', message='This is a sample warning!')

It works on my computer but when I built it for android and run it on my phone, the app crashes when it tries to send a notification. It says that there's no attribute icon for the app in _set_icons.py. I tried to look into it, but I don't know what should I do.

buildozer.spec

requirements = python3,kivy,plyer,android

logs

09-21 15:40:00.332 18207 18233 I python : File "/home/masterjoseph/notif-test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/notificationtest/plyer/platforms/android/notification.py", line 100, in _set_icons
09-21 15:40:00.332 18207 18233 I python : AttributeError: type object 'com.test.notification.R$drawable' has no attribute 'icon'
09-21 15:40:00.332 18207 18233 I python : Python for android ended.

@kyudorimj
Copy link
Contributor Author

kyudorimj commented Sep 24, 2021

After days of researching, coding and debugging, I have finally figured out the error and fixed it with a work-around.

The logs returns an AttributeError which says:
AttributeError: type object 'com.test.notification.R$drawable' has no attribute 'icon'

It turns out that the class R$drawable no longer has an icon attribute but has a presplash attribute. Just like the icon, this attribute is also a png and can be replaced.

So in plyer/platforms/android/notification.py, in line 100 I made this changes:

from:

 app_icon = Drawable.icon

change to:

 app_icon = Drawable.presplash

Then it works!

Ps. This is not a resoultion as stated by @lydiym, just a workaround to make the app works.

@kyudorimj kyudorimj changed the title Notification for android not working Notification for android not working [ Drawable.icon ] Sep 25, 2021
@lydiym
Copy link

lydiym commented Sep 27, 2021

Hello! Issue is still actual. Build sources patching isn't good resolution. It should be fixed in plyer sources.

@kyudorimj kyudorimj reopened this Sep 28, 2021
@kyudorimj
Copy link
Contributor Author

It should be fixed in plyer sources.

Hello, you are right. I reopened the issue and edited my last comment. Thanks :)

@kyudorimj
Copy link
Contributor Author

PR is now merged and the issue is now fixed! Thank y'all. ❤️

@MiiKyyz
Copy link

MiiKyyz commented Nov 20, 2021

hey i am having problems on this, i am on windows

@kyudorimj
Copy link
Contributor Author

What problem @MiiKyyz

@MiiKyyz
Copy link

MiiKyyz commented Nov 21, 2021 via email

@kyudorimj
Copy link
Contributor Author

The problem on trying to push a notification on my Android. I have tried everything but nothing works

How do you install plyer? What OS are you using?

Plyer latest release (Release v2.0.0) was on last Nov 2020, the merged commits since then are not yet included when you install plyer using pip install plyer. The workaround is to reinstall it using the latest master branch in this repo. To do that you need to run:

pip install https://github.com/kivy/plyer/archive/refs/heads/master.zip

Also, if you are using buildozer to build to apk, you need to specify the same link on your requirements instead of using plyer.

 requirements = python,kivy,https://github.com/kivy/plyer/archive/refs/heads/master.zip

Hope this helps.

@MiiKyyz
Copy link

MiiKyyz commented Nov 26, 2021 via email

@MiiKyyz
Copy link

MiiKyyz commented Dec 2, 2021 via email

@kyudorimj
Copy link
Contributor Author

python3,kivy==2.0.0,mysql_connector

Hi have you find solution with this?

I think you need to use mysql-connector or mysql-connector-python.

If that doesn't work, you should find solution on mysql docs or ask on mysql repo issues.

@MiiKyyz
Copy link

MiiKyyz commented Dec 28, 2021 via email

@TukendraKulkarni
Copy link

You seem to use localhost. I don't have whole idea about your project but I don't think that will work. Try using public ip. You can take help of google cloud platform

@NikitaKokarev
Copy link

hey i am having problems on this, i am on windows

Hope this solution to send Android notifications using Plyer can be helpful to someone:
https://github.com/NikitaKokarev/PlyerNotification
I changed the plyer notification logic depending on api_version >= 31.

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

5 participants