33import os ,re
44import threading
55from .an_types import Importance
6+ from .an_utils import can_accept_arguments
67from .styles import NotificationStyles
78from .base import BaseNotification
89DEV = 0
@@ -218,7 +219,7 @@ def setBigPicture(self,path):
218219
219220 def setSmallIcon (self ,path ):
220221 """
221- sets small icon to the top right
222+ sets small icon to the top left
222223 :param path: can be `Relative Path` or `URL`
223224 :return:
224225 """
@@ -241,6 +242,10 @@ def setLargeIcon(self,path):
241242 print ('Done setting large icon' )
242243
243244 def setBigText (self ,body ):
245+ """Sets a big text for when drop down button is pressed
246+
247+ :param body: The big text that will be displayed
248+ """
244249 if ON_ANDROID :
245250 big_text_style = NotificationCompatBigTextStyle ()
246251 big_text_style .bigText (str (body ))
@@ -526,8 +531,13 @@ def addNotificationStyle(self,style:str,already_sent=False):
526531 return True
527532
528533 def __dispatch_notification (self ):
529- self .notification_manager .notify (self .__id , self .__builder .build ())
530-
534+ if NotificationHandler .has_permission ():
535+ self .notification_manager .notify (self .__id , self .__builder .build ())
536+ else :
537+ print ('Permission not granted to send notifications' )
538+ # Not asking for permission too frequently, This makes dialog popup to stop showing
539+ # NotificationHandler.asks_permission()
540+
531541 def __start_notification_build (self , persistent , close_on_click ):
532542 self .__create_basic_notification (persistent , close_on_click )
533543 if self .style not in ['simple' ,'' ]:
@@ -768,7 +778,7 @@ class NotificationHandler:
768778 """For Notification Operations """
769779 __name = None
770780 __bound = False
771-
781+ __requesting_permission = False
772782 @classmethod
773783 def get_name (cls ):
774784 """Returns name or id str for Clicked Notification."""
@@ -876,22 +886,38 @@ def has_permission():
876886 return check_permission (Permission .POST_NOTIFICATIONS )
877887
878888 @classmethod
889+ @run_on_ui_thread
879890 def asks_permission (cls ,callback = None ):
880891 """
881892 Ask for permission to send notifications if needed.
893+ Passes True to callback if access granted
882894 """
883- if not ON_ANDROID :
884- return
885- def on_permissions_result ( permissions , grant ):
886- print ( "Permission Grant State: " , grant )
895+ if cls . __requesting_permission or not ON_ANDROID :
896+ return True
897+
898+ def on_permissions_result ( permissions , grants ):
887899 try :
888900 if callback :
889- callback ()
901+ if can_accept_arguments (callback , True ):
902+ callback (grants [0 ])
903+ else :
904+ callback ()
890905 except Exception as request_permission_error :
891906 print ('Exception: ' ,request_permission_error )
892- print ('Permission request callback error: ' ,traceback .format_exc ())
907+ print ('Permission response callback error: ' ,traceback .format_exc ())
908+ finally :
909+ cls .__requesting_permission = False
910+
893911 if not cls .has_permission ():
912+ cls .__requesting_permission = True
894913 request_permissions ([Permission .POST_NOTIFICATIONS ],on_permissions_result )
914+ else :
915+ cls .__requesting_permission = False
916+ if callback :
917+ if can_accept_arguments (callback ,True ):
918+ callback (True )
919+ else :
920+ callback ()
895921
896922
897923NotificationHandler .bindNotifyListener ()
0 commit comments