Skip to content

Conversation

hkparker
Copy link
Contributor

Description:

This is a work in progress to get android notifications to use a good icon. Experimentation reveals we have some choices to make about how icons are defined in Fyne, discussion below.

Fixes #936

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

@hkparker hkparker marked this pull request as draft April 14, 2025 17:47
@coveralls
Copy link

Coverage Status

coverage: 62.272%. remained the same
when pulling 022f0d2 on hkparker:hayden-android-notification-icon
into f2ccdfa on fyne-io:develop.

@hkparker
Copy link
Contributor Author

This code works... if your icon is white.

Android design specifications require an all-white small icon for notifications (more or less, additional reading), because they use that to create small silhouettes. If you pass in an icon with a color, you just get a box (or circle) and android refuses to render it.

Here's an example of what an app looks like with an all-white icon:

Screenshot_20250414-125006
Screenshot_20250414-125025
Screenshot_20250414-125035
Screenshot_20250414-125043

And here's when I try the default Fyne icon:

Screenshot_20250414-125208
Screenshot_20250414-125222
Screenshot_20250414-125230
Screenshot_20250414-125237

So I think we either need to support a --notification-icon option in fyne package (sounds like a lot), or auto-generate an all white version of whatever people set as their icon (sounds like it often won't look good). The small icon is a requirement, so we'll have to have something here.

Would love to hear any other ideas and contribute what I can to this.

@andydotxyz
Copy link
Member

I think the same style of icon is required to make the "adaptive icons" (matching system theme) work for Android as well.

Might be good to auto-generate by default (strip out background and make the rest white?) but provide the option for something in the metadata perhaps "silhouette icon" or "outline icon" that we can use in these cases?

@hkparker
Copy link
Contributor Author

Stripping out the background and making the rest white will be a complicated task. If it is true that greyscale icons work (can check), then I'd say we should just make the icon greyscale by default, and yes supporting a different icon type for this in the metadata would be worth including as part of this I think

@hkparker
Copy link
Contributor Author

Greyscale icons do not work on my device

@andydotxyz
Copy link
Member

It shouldn't be too tough to convert all pixels that are BG (the top left or most common of all 4 corners colour) to transparent. After that all visible pixels go white.

@hkparker
Copy link
Contributor Author

My launcher icon background is a white circle, which is a pretty common pattern. If the white circle is identified as the background and made transparent, and the rest made white, that would work really well in my case, and a few other examples I can see on my phone.

So in the tools repo, I suspect one of the packaging steps would be to generate this icon and add it to the android manifest somehow so that we can reference it in this part of the code? Then allow for an override to what that reference points to.

@andydotxyz
Copy link
Member

Sounds good.
Other than the circle background - with android OS supporting different icon shapes it is not good to assume you have a circle icon. But that will be more important as we add support to the adaptive icons. (search "different shapes" at https://developer.android.com/develop/ui/views/launch/icon_design_adaptive)

@hkparker
Copy link
Contributor Author

RIght, we shouldn't assume a circle, it's just a common pattern, so whatever we do shouldn't break with a circle.

Adaptive icons are cool! I wasn't aware of this.

@andydotxyz
Copy link
Member

RIght, we shouldn't assume a circle, it's just a common pattern, so whatever we do shouldn't break with a circle.

What is the rest of the icon outline if the background is only a circle shape?

jobject appInfo = (*env)->CallObjectMethod(env, (jobject)ctx, getApplicationInfoMethod);
jclass applicationInfoClass = find_class(env, "android/content/pm/ApplicationInfo");
jfieldID iconFieldID = (*env)->GetFieldID(env, applicationInfoClass, "icon", "I");
jint iconID = (*env)->GetIntField(env, appInfo, iconFieldID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very glad you tracked this down. Feels like the hard part is already done :). Now we just need to get the API right for the icon types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope it's useful! I got familiar with the JNI stuff doing the battery optimization calls, so I'm happy to dive into more JNI where it's needed.

@hkparker
Copy link
Contributor Author

Not 100% sure I understand the question, but I think the answer is transparency. I have a square transparent PNG, containing a white circle, with my logo in it

@andydotxyz
Copy link
Member

Not 100% sure I understand the question, but I think the answer is transparency. I have a square transparent PNG, containing a white circle, with my logo in it

Thanks, that is what I was asking. In that case (icons not matching the recommended square non-transparent) then maybe we see transparent pixel and do no transformation and allow the app to override. At least they the silhouette will be right which may in cases be all that was wanted.

@Jacalz Jacalz changed the title use the application icon for notifications Use application icon for notifications on Android Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants