我知道这是一个老问题,但 UrbanAirship 经常更新,所以我决定帮助可能访问此页面的其他人。从 6.0.1 版开始,BasicNotificationBuilder
不再有。为了使用图标和颜色等自定义通知,您需要扩展NotifcationFactory
类并覆盖该createNotification
方法。
如下例所示:
public class MyNotificationFactory extends NotificationFactory {
public MyNotificationFactory(Context context){
super(context);
}
@Override
public Notification createNotification(PushMessage pushMessage, int i) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
.setContentTitle(getContext().getResources().getString(R.string.app_name))
.setContentText(pushMessage.getAlert())
.setSmallIcon(R.drawable.your_icon_here)
.setColor(getContext().getResources().getColor(R.color.your_color_here))
.setAutoCancel(true);
return builder.build();
}
@Override
public int getNextId(PushMessage pushMessage) {
return NotificationIDGenerator.nextID();
}
}
最后,您必须在应用程序类或初始化 UA 的任何位置将其设置为 UrbanAirship 的新通知工厂:
UAirship.shared().getPushManager().setNotificationFactory(new MyNotificationFactory(getApplicationContext()));