Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust way to get application icon on Android for notification #669

Merged
merged 1 commit into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Zen-CODE marked this conversation as resolved.
Show resolved Hide resolved
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