【发布时间】:2023-02-23 15:15:22
【问题描述】:
我有一个简单的代码,使用 plyer 显示通知。
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
from plyer import notification
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.properties import DictProperty
from kivy.uix.label import Label
Builder.load_string("""
<NotificationDemo>:
BoxLayout:
Label:
id: notification_text
text: 'Hi user'
font_size:50
""")
a=0
class NotificationDemo(BoxLayout):
kwargs = DictProperty()
def update(self,dt):
global a
try:
a = a + 1
sms = str(a)
self.ids.notification_text.text = sms
notification.notify(title='hello' , message=sms)
except Exception as error:
self.ids.notification_text.text = str(error)
class ServiceApp(App):
def build(self):
fdir = NotificationDemo()
Clock.schedule_interval(fdir.update, 6)
return fdir
def on_pause(self):
return True
if __name__ == '__main__':
ServiceApp().run()
此代码在 Windows 和低版本 Android 上正常工作。但是当我在 Android 13 上运行这段代码时,出现以下错误。
发生 JVM 异常:org.test.notify:Targeting S+(版本 31 及以上)要求在创建 Pendingintent 时指定 FLAG_IMMUTABLE 或 FLAG MUTABLE 之一。强烈考虑使用 FLAG_IMMUTABLE,只有在某些功能依赖于 Pendingintent 可变时才使用 FLAG_MUTABLE,例如如果它需要与内联回复或气泡一起使用。 java.lang.IllegalArgumentException异常
我看过类似的问题here 和here 但他们没有答案。 我应该使用该服务吗?或者我应该在 buildozer.spec 中做些什么? 我真的很感激你能提供的任何帮助。
【问题讨论】:
-
plyer repo github.com/kivy/plyer/issues/702 中有一个匹配的开放问题
-
谢谢。这个问题没有答案