Skip to content

Commit

Permalink
More robust way to get application icon on Android for notification (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rdb committed May 4, 2022
1 parent 43c4d28 commit 8a6ae05
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions plyer/platforms/android/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
Context = autoclass('android.content.Context')
NotificationBuilder = autoclass('android.app.Notification$Builder')
NotificationManager = autoclass('android.app.NotificationManager')
Drawable = autoclass("{}.R$mipmap".format(activity.getPackageName()))
PendingIntent = autoclass('android.app.PendingIntent')
Intent = autoclass('android.content.Intent')
Toast = autoclass('android.widget.Toast')
Expand All @@ -41,8 +40,17 @@ class AndroidNotification(Notification):
'''

def __init__(self):
package_name = activity.getPackageName()
self._ns = None
self._channel_id = activity.getPackageName()
self._channel_id = package_name

pm = activity.getPackageManager()
info = pm.getActivityInfo(activity.getComponentName(), 0)
if info.icon == 0:
# Take the application icon instead.
info = pm.getApplicationInfo(package_name, 0)

self._app_icon = info.icon

def _get_notification_service(self):
if not self._ns:
Expand Down Expand Up @@ -87,8 +95,7 @@ def _toast(self, message):
Toast.LENGTH_LONG
).show()

@staticmethod
def _set_icons(notification, icon=None):
def _set_icons(self, notification, icon=None):
'''
Set the small application icon displayed at the top panel together with
WiFi, battery percentage and time and the big optional icon (preferably
Expand All @@ -97,7 +104,7 @@ def _set_icons(notification, icon=None):
.. versionadded:: 1.4.0
'''
app_icon = Drawable.icon
app_icon = self._app_icon
notification.setSmallIcon(app_icon)

bitmap_icon = app_icon
Expand Down

0 comments on commit 8a6ae05

Please sign in to comment.