phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.31k stars 996 forks source link

How to implement custom setSmallIcon PNG icon #487

Open andreszs opened 9 years ago

andreszs commented 9 years ago

I want to set my white icon for the notification bar, and I tried all possible options so far:

.setSmallIcon(my.app.name.R.drawable.noticon)
.setSmallIcon(R.drawable.noticon)
.setSmallIcon(android.R.drawable.noticon)
.setSmallIcon(res.getIdentifier("noticon", "drawable", context.getPackageName()))

And placed noticon.png on: MyApp\plugins\com.phonegap.plugins.PushPlugin\src\android\res\drawable-hdpi + all other drawable dirs MyApp\platforms\android\res\drawable + all other drawable dirs

I keep getting the default, colored icon instead my white noticon.png. Any help will be appreciated, thanks.

adamsc64 commented 9 years ago

The following steps worked for me:

  1. Add to platforms/android/src/com/plugin/gcm/GCMIntentService.java the line to import the R generated by cordova, import com.myapp.www.R; - not the R from android.
  2. Add noticon.png to ./platforms/android/ant-build/res/drawable/
  3. Use setSmallIcon(R.drawable.noticon);

There must be a better way to do this than what I did however. Defaulting to setSmallIcon(context.getApplicationInfo().icon), as PushPlugin does right now, is not desirable in many cases. Many developers want their application's icon to be different from the notification's icon. This seems like a normal requirement inasmuch as many application icons are in color, while notification icons need to be entirely white.

So I don't know what the right answer is right now.

mladenp commented 9 years ago

This is a real problem if your target SDK is Lollipop because it allows only flat icons, and turn your icon to white. So we most definitely need an option to choose custom notification icon.

bitsmuggler commented 9 years ago

@adamsc64 Step 2 isn't correct. The noticon.png should be copied into ./platforms/android/res/drawable Regards, patrick

barryvdh commented 9 years ago

I've added an Image asset to the resources in Android Studio, with the Notification icon type (so it makes correct silhouettes).

And the following code: .setSmallIcon(context.getResources().getIdentifier("ic_stat_name", "drawable", context.getPackageName()))

stevenmusumeche commented 9 years ago

@barryvdh where do you add the setSmallIcon code in Android Studio?

barryvdh commented 9 years ago

In one of the source files, where they add the icon. But https://github.com/phonegap/phonegap-plugin-push solved my problems better :)