React-native-track-player: [Android] Custom notification icon does not appear in debug builds. (Works in release builds)

Created on 5 Mar 2019  Â·  32Comments  Â·  Source: react-native-kit/react-native-track-player

I'm using this code to show icon on notification but it does not show up.

```
TrackPlayer.setupPlayer();
TrackPlayer.updateOptions({
stopWithApp: true,
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
TrackPlayer.CAPABILITY_STOP
],
compactCapabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE
],

        icon: require('./../imgs/ic_logo_notification.png'),
    });```

Am I doing something wrong?

Android wontfix

Most helpful comment

@ithustle It doesn't make sense to have ic_logo_notification.png and [email protected] at the same time.

To follow Android specification more strictly, try this:

Since Android 5, your icon should have transparent background and be entirely white.
You can use this tool to generate the image files: https://romannurik.github.io/AndroidAssetStudio/icons-notification.html

All 32 comments

If you want to show icon in notification. You need to add that as follows

TrackPlayer.add({ // Other params comes here as usual like url, title etc artwork:require('./../imgs/ic_logo_notification.png') //this is your notification icon });

@ManeeshAkurathi are you sure about this?

AFAIK artwork: require('...') show audio cover on nofication controllers ...

Can you send a screenshot showing the how the notification looks to you? Can you also send the icon image?

@Guichaguri , please FIA.

Now I figure it out that happens on device with differents sizes, because I tested on a different device and show up.
My icon has 33 x 33 px

ic_logo_notification

screenshot_20190306-120139

@ithustle It worked for me.

@ManeeshAkurathi is it works on different screens sizes?

I reopened this discussion because this issue still ...

@ithustle any update on the issue?

Hi,
It resolve this issue by added one more icon to drawable of android name icon and passed it as a default value to the method in MetadataManager.java file.

builder.setSmallIcon(getIcon(options, "icon", R.drawable.icon));

@ishigamii do you have the icon image in different scales (the filename ending with @2x, @3x, etc)?

@Guichaguri I think you mistook me with the tag ;)

Sorry for that. That was meant for @ithustle

@Guichaguri, yep

Captura de ecrã de 2019-07-01 14-02-20

Icon does not work for me either.
react-native-track-player: 1.1.4
react-native: 0.55.3

TrackPlayer.updateOptions({
      stopWithApp: true,
      alwaysPauseOnInterruption: true,
      icon: require('../assets/img/logo.png'),
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
        TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
        TrackPlayer.CAPABILITY_STOP,
      ],
      compactCapabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
      ],
});

@ithustle It doesn't make sense to have ic_logo_notification.png and [email protected] at the same time.

To follow Android specification more strictly, try this:

Since Android 5, your icon should have transparent background and be entirely white.
You can use this tool to generate the image files: https://romannurik.github.io/AndroidAssetStudio/icons-notification.html

Thanks, @Guichaguri . That it is I had asking before. :)
I'll try do this.

@Guichaguri... well, this is awkward but still no working :(

I was facing the same problem. It seems that while developing it will only display the default play icon, but with the release build installed (gradlew installRelease), it gave me my desired notification icon.

(I'm on RN 0.60.5 and version 1.1.8 of this package)

@ithustle Are you still facing this issue?

Any chance it was only failing on debug builds?

@curiousdustin , for now I'm not worried about it. Maybe in next days I'll keep my eyes on it. But yeah, I still facing this issue.

Please let us know if it is happening on debug and/or release builds.

some body please give some solutions i can't see a notification icon only art work

Are you testing a release build?

To clarify, the icon being discussed in this thread is the icon that appears in the status bar at the top of the screen. Separate from the actual notification.

I confirm that the notification icon is working in release build but it is not working in debug build.

Me too

Why did you removed it the thing is still unsolved

I removed the question label because I consider this a confirmed bug at this point. Custom icon does not appear in debug builds.

Ohh okay nice

On Wed, Apr 29, 2020, 4:50 PM Dustin Bahr notifications@github.com wrote:

I removed the question label because I consider this a confirmed bug at
this point. Custom icon does not appear in debug builds.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/react-native-kit/react-native-track-player/issues/475#issuecomment-621221402,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AIFSPYTFSCWAPGPTYJNIL7TRPAWBPANCNFSM4G36UQUQ
.

In short, it's not fixable. Android requires bundled assets for notification icons, and since the icons in debug mode are not bundled but retrieved from a local server, it won't work.

In short, it's not fixable. Android requires bundled assets for notification icons, and since the icons in debug mode are not bundled but retrieved from a local server, it won't work.

It is required to set bundleInDebug to true as it's by default set to false.

project.ext.react = [
    bundleInDebug: true,
]

Reference: https://github.com/facebook/react-native/blob/88f2356eedf71183d02cde0826c8a0c6910f83dd/template/android/app/build.gradle#L26-L27

const options = {
  icon: { uri: 'app_icon' }
}
TrackPlayer.updateOptions(options)

Reference: https://reactnative.dev/docs/images#images-from-hybrid-apps-resources

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moduval picture moduval  Â·  3Comments

mnlbox picture mnlbox  Â·  4Comments

fabiocosta88 picture fabiocosta88  Â·  3Comments

EhteshamAnwar picture EhteshamAnwar  Â·  3Comments

RiccardoNL picture RiccardoNL  Â·  3Comments