Plyer 通知在 Android 上不起作用

问题描述 投票:0回答:2

我正在尝试编写一个简单的应用程序来接收消息并显示通知,除了通知之外一切正常。
此外,如果我在 Windows 上运行该应用程序,它可以正确显示通知
我在 Android 10 上运行该应用程序

我用于通知的代码是:

from plyer import notification
notification.notify(title="Notification", message=message)

当我在手机上运行该应用程序时出现此错误(adb logcat):

'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
11-09 16:18:15.526 10656 16558 I python  : Android kivy bootstrap done. __name__ is __main__
11-09 16:18:15.526 10656 16558 I python  : AND: Ran string
11-09 16:18:15.526 10656 16558 I python  : Run user program, change dir and execute entrypoint
11-09 16:18:15.598 10656 16558 I python  : [WARNING] [Config      ] Older configuration version detected (0 instead of 21)
11-09 16:18:15.598 10656 16558 I python  : [WARNING] [Config      ] Upgrading configuration in progress.
11-09 16:18:15.601 10656 16558 I python  : [INFO   ] [Logger      ] Record log in /data/user/0/org.foo.foo/files/app/.kivy/logs/kivy_20-11-09_0.txt
11-09 16:18:15.601 10656 16558 I python  : [INFO   ] [Kivy        ] v1.11.1
11-09 16:18:15.601 10656 16558 I python  : [INFO   ] [Kivy        ] Installed at "/data/user/0/org.foo.foo/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
11-09 16:18:15.601 10656 16558 I python  : [INFO   ] [Python      ] v3.8.1 (default, Nov  8 2020, 16:20:13)
11-09 16:18:15.601 10656 16558 I python  : [Clang 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec7462
11-09 16:18:15.602 10656 16558 I python  : [INFO   ] [Python      ] Interpreter at ""
11-09 16:18:16.063 10656 16558 I python  : [INFO   ] [Factory     ] 184 symbols loaded
11-09 16:18:16.225 10656 16558 I python  : [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
11-09 16:18:16.254 10656 16558 I python  : [INFO   ] [Text        ] Provider: sdl2
11-09 16:18:16.344 10656 16558 I python  : [INFO   ] [Window      ] Provider: sdl2
11-09 16:18:16.369 10656 16558 I python  : [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
11-09 16:18:16.371 10656 16558 I python  : [INFO   ] [GL          ] Backend used <sdl2>
11-09 16:18:16.371 10656 16558 I python  : [INFO   ] [GL          ] OpenGL version <b'OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###'>
11-09 16:18:16.371 10656 16558 I python  : [INFO   ] [GL          ] OpenGL vendor <b'ARM'>
11-09 16:18:16.371 10656 16558 I python  : [INFO   ] [GL          ] OpenGL renderer <b'Mali-G76'>
11-09 16:18:16.372 10656 16558 I python  : [INFO   ] [GL          ] OpenGL parsed version: 3, 2
11-09 16:18:16.372 10656 16558 I python  : [INFO   ] [GL          ] Texture max size <8192>
11-09 16:18:16.372 10656 16558 I python  : [INFO   ] [GL          ] Texture max units <16>
11-09 16:18:16.388 10656 16558 I python  : [INFO   ] [Window      ] auto add sdl2 input provider
11-09 16:18:16.388 10656 16558 I python  : [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
11-09 16:18:16.446 10656 16558 I python  : [INFO   ] [GL          ] NPOT texture support is available
11-09 16:18:16.461 10656 16558 I python  : [WARNING] [Base        ] Unknown <android> provider
11-09 16:18:16.462 10656 16558 I python  : [INFO   ] [Base        ] Start application main loop
11-09 16:18:36.173 10656 16801 I python  :  Traceback (most recent call last):
11-09 16:18:36.173 10656 16801 I python  :    File "/mnt/c/Users/User/PycharmProjects/Foo/mobile_app/android_package/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/foo/plyer/utils.py", line 96, in _ensure_obj
11-09 16:18:36.173 10656 16801 I python  :    File "/mnt/c/Users/User/PycharmProjects/Foo/mobile_app/android_package/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/foo/plyer/platforms/android/notification.py", line 30, in <module>
11-09 16:18:36.174 10656 16801 I python  :    File "/mnt/c/Users/User/PycharmProjects/Foo/mobile_app/android_package/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/foo/jnius/reflect.py", line 208, in autoclass
11-09 16:18:36.175 10656 16801 I python  :    File "jnius/jnius_export_func.pxi", line 28, in jnius.jnius.find_javaclass11-09 16:18:36.175 10656 16801 I python  :  jnius.jnius.JavaException: Class not found b'org/foo/foo/R$drawable'

如果有用,我的 buildozer.spec 文件是:buildozer.spec

我真的不明白出了什么问题,有人可以帮助我吗?

python android kivy buildozer
2个回答
0
投票

在 android 的 notification.py 中将 R$drawable 更改为 R$mipmap


在 plyer 资源文件中,有 notification.py 文件,路径为 plyer/platforms/android/notification.py。然后,只需更改第29行 来自:

Drawable = autoclass("{}.R$drawable".format(activity.getPackageName()))

至:

Drawable = autoclass("{}.R$mipmap".format(activity.getPackageName()))

参考:


0
投票

我在这里解决了这个问题: https://github.com/NikitaKokarev/PlyerNotification 使用 ./data/legal_icons 目录。

© www.soinside.com 2019 - 2024. All rights reserved.