我在android中使用Urban Airship推送通知插件。一切正常,但在上面的Android 4.4推送通知图标变为白色,没有显示通知图标。此问题仅出现在Lolypop(> 4.4)中。感谢任何帮助。
答案 0 :(得分:8)
针对SDK 21(Lollipop)图标的应用似乎会自动过滤为白色 - Notification bar icon turns white in Android 5 Lollipop。因此,要解决此问题,您可以将目标SDK版本设置为20,或者您可以手动修改Urban Airship phonegap插件并通过将https://github.com/urbanairship/phonegap-ua-push/blob/master/src/android/PushAutopilot.java中的execute方法替换为以下内容来手动设置图标:
@Override
public void execute(final Application application) {
// Parse cordova config options
AirshipOptions configOptions = new AirshipOptions(application);
final boolean enablePushOnLaunch = configOptions.getBoolean(ENABLE_PUSH_ONLAUNCH, false);
UAirship.takeOff(application, getAirshipConfig(application, configOptions), new UAirship.OnReadyCallback() {
@Override
public void onAirshipReady(UAirship airship) {
// Create a new notification factory
DefaultNotificationFactory defaultNotificationFactory = new DefaultNotificationFactory(application);
// Customize the notification icon and accent color
defaultNotificationFactory.setSmallIconId(R.drawable.ic_notification);
defaultNotificationFactory.setColor(NotificationCompat.COLOR_DEFAULT);
// Set the factory
airship.getPushManager().setNotificationFactory(defaultNotificationFactory);
if (enablePushOnLaunch) {
airship.getPushManager().setUserNotificationsEnabled(true);
}
}
});
}
将R.drawable_ic_notification
替换为项目中包含的图标。
更新: 发布3.0.0的插件,允许您在配置中指定强调颜色和可绘制名称,而无需修改任何代码。
<!-- Override the Android notification icon -->
<preference name="com.urbanairship.notification_icon" value="ic_notification" />
<!-- Specify the notification accent color for Android API 21+ (Lollipop) -->
<preference name="com.urbanairship.notification_accent_color" value="#0000ff" />
可在此处找到更多信息 - https://github.com/urbanairship/phonegap-ua-push