gpt4 book ai didi

python - Plyer 通知在 android 上不起作用

转载 作者:行者123 更新时间:2023-12-04 23:50:51 33 4
gpt4 key购买 nike

我正在尝试编写一个接收消息并显示通知的简单应用程序,除了通知之外一切正常。
此外,如果我在 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
我真的无法理解出了什么问题,有人可以帮助我吗?

最佳答案

将 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()))
引用:
  • https://github.com/kivy/plyer/blob/master/plyer/platforms/android/notification.py
  • https://github.com/kivy/plyer/pull/648
  • https://github.com/kivy/plyer/issues/647
  • 关于python - Plyer 通知在 android 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64755156/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com