[android]JPush自定义通知栏

自定义通知栏

先自定义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,发送时指定编号发送。

\


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值