Skip to main content

系统通知

from ascript.android.system import Notification

通知监听

warning

调用该方法,会触发权限请求.请在设备上开启监听权限.

您也可以在APP设置中,开启系统监听.

获取手机SD卡目录

  • 函数
Notification.listen(tunner):
  • 参数
参数类型是否必填说明
tunnerfun(notiobj)python函数,必须带有1个形参
  • 示例
# 监听系统通知
from ascript.android.system import Notification
from android.app import Notification as AndroidNoti

def noti_callback(n):
print(n)
print("隶属包名",n.getPackageName())
print("标签",n.getTag())
print("ID",n.getId())
print("时间",n.getPostTime())
print("通知",n.getNotification())
# 获取通知对象
# 获取 通知-额外数据对象
android_noti = n.getNotification()
bundle = android_noti.extras
title = bundle.getString(AndroidNoti.EXTRA_TITLE)
print("标题",title)
text = bundle.getString(AndroidNoti.EXTRA_TEXT)
print("内容",text)
# 获取通知意图
intent = android_noti.contentIntent
print(intent)

Notification.listen(noti_callback)