自定义通知栏
我试图更改下来通知栏里的icon,各种方法都试过,文档看了无数遍,发现这个图标是不可更改的,永远和APP程序图标一样的。。
先自定义Receiver
private static final String TAG = "MyReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
Log.i(TAG, "JPush用户注册成功");
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent
.getAction())) {
Log.i(TAG, "接受到推送下来的自定义消息");
receivingNotification(context, bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent
.getAction())) {
Log.i(TAG, "接受到推送下来的通知");
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent
.getAction())) {
Log.i(TAG, "用户点击打开了通知");
openNotification(context, bundle);
}
}
在receivingNotification()中自定义notification通知栏
private void receivingNotification(Context context, Bundle bundle) {
NotificationManager manager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
// 使用notification
// 使用广播或者通知进行内容的显示
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
builder.setContentText(message).setSmallIcon(R.drawable.notification_icon_2).setContentTitle(JPushInterface.EXTRA_TITLE);
builder.setDefaults(Notification.DEFAULT_SOUND);
manager.notify(1,builder.build());
}
我试图更改下来通知栏里的icon,各种方法都试过,文档看了无数遍,发现这个图标是不可更改的,永远和APP程序图标一样的。。
官网提供的一种简版
还有一种简版的,也是官网demo,mark一下。设置成默认,发送通知
BasicPushNotificationBuilder builder2 = new BasicPushNotificationBuilder(
MainActivity.this);
builder2.statusBarDrawable = R.drawable.logo;
builder2.notificationFlags = Notification.FLAG_AUTO_CANCEL; // 设置为自动消失
builder2.notificationDefaults = Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS; // 设置为铃声与震动都要
JPushInterface.setDefaultPushNotificationBuilder(builder2);
JPushInterface.setPushNotificationBuilder(2, builder2);
setPushNotificationBuilder(2, builder2);设置builder2的样式编号为2,发送时指定编号发送。