android自定义push通知_[android]JPush自定义通知栏

本文介绍了如何在Android中自定义极光推送(JPush)的通知栏显示,包括自定义Receiver接收消息,设置通知内容和图标,以及实现下拉效果。讨论了statusBarDrawable和layoutIconDrawable的区别,并提供了不同类型的自定义通知示例。
摘要由CSDN通过智能技术生成

JPush嵌入工程

自定义通知栏

先自定义Receiver

android:name="Your Receiver"

android:enabled="true">

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程序图标一样的。。

带有下拉效果

还有一种自定义通知栏,带有下拉效果。是官网介绍的。

布局文件customer_notitfication_layout.xml

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

/>

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_marginLeft="10dip"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#286CA6"

android:textSize="20sp"

/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#6FA45E"

android:textSize="16sp"

/>

初始化通知效果

CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(

MainActivity.this, R.layout.customer_notitfication_layout,

R.id.icon, R.id.title, R.id.text);

// 指定定制的 Notification Layout

builder.statusBarDrawable = R.drawable.notification_icon;

// 指定最顶层状态栏小图标

builder2.layoutIconDrawable = R.drawable.notification_icon;

// 指定下拉状态栏时显示的通知图标

JPushInterface.setPushNotificationBuilder(1, builder1);

这里面有一个方法builder.statusBarDrawable,这个设置的是一个状态栏图标,不是下拉界面里那个。当来通知时,手机顶部会滚动提示一下来消息了。这里设置的图标就是刚来通知在顶部提示的,而不是上图里红框里那个。

这种带下来效果

官网提供的一种简版

还有一种简版的,也是官网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,发送时指定编号发送。

原文:http://blog.csdn.net/bless2015/article/details/46623569

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值