android 自定义推送布局_关于Android的极光推送的自定义消息栏

Android 收到推送的消息的改变,

在收到通知的时候无法改变通知栏显示的时候i,一般通知在Android上只显示一行,此时我们该怎么版呢?

在经过好长时间的不断查阅之下,做出了自己想要的效果,在手到推销消息的时候能狗多行显示,

在无奈之下,只好将通知改为自定义消息了,话不多说,直接上代码:

public class MyReceiver extends BroadcastReceiver{

private static finalStringTAG="JIGUANG-Example";

public voidonReceive(Contextcontext,Intentintent) {

try{

Bundle bundle=intent.getExtras();

if(JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {

String regId=bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);

//send the Registration Id to your server...

}else if(JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {

Log.d(TAG,"接收到推送下来的自定义消息: "+bundle.getString(JPushInterface.EXTRA_MESSAGE));

receivingNotification(context,bundle);

}else if(JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {

Log.d(TAG,"接收到推送下来的通知");

intnotifactionId=bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);

Log.d(TAG,"接收到推送下来的通知的ID: "+notifactionId);

receivingNotification(context,bundle);

}else if(JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {

Log.d(TAG,"用户点击打开了通知");

//打开自定义的Activity

Intent i=newIntent(context,TestActivity.class);

i.putExtras(bundle);

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);

context.startActivity(i);

}else if(JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {

Log.d(TAG,"用户收到到RICH PUSH CALLBACK: "+bundle.getString(JPushInterface.EXTRA_EXTRA));

//在这里根据JPushInterface.EXTRA_EXTRA的内容处理代码,比如打开新的Activity, 打开一个网页等..

}else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {

booleanconnected=intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE,false);

Log.w(TAG,""+intent.getAction()+" connected state change to "+connected);

}else{

}

}catch(Exceptione) {

}

}

//打印所有的intent extra数据

private staticString printBundle(Bundlebundle) {

StringBuilder sb=newStringBuilder();

for(String key:bundle.keySet()) {

if(key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {

sb.append("\nkey:"+key+", value:"+bundle.getInt(key));

}else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {

sb.append("\nkey:"+key+", value:"+bundle.getBoolean(key));

}else if(key.equals(JPushInterface.EXTRA_EXTRA)) {

if(TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {

Log.i(TAG,"This message has no Extra data");

continue;

}

try{

JSONObject json=newJSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));

Iteratorit=json.keys();

while(it.hasNext()) {

String myKey=it.next();

sb.append("\nkey:"+key+", value: ["+

myKey+" - "+json.optString(myKey)+"]");

}

}catch(JSONExceptione) {

Log.e(TAG,"Get message extra JSON error!");

}

}else{

sb.append("\nkey:"+key+", value:"+bundle.getString(key));

}returnsb.toString();}

//想要改变自定义消息的时候,这里是关键

@RequiresApi(api=Build.VERSION_CODES.JELLY_BEAN)

private voidreceivingNotification(Contextcontext,Bundlebundle) {

String message=bundle.getString(JPushInterface.EXTRA_MESSAGE);

RemoteViews customView=newRemoteViews(context.getPackageName(),R.layout.notifycation_layout);

//最终要的就是布局,如果是想要通知蓝里变的内容随之变化的话,就必须要给最外层的布局高度给一个定值布局在后边

customView.setTextViewText(“自定义布局里边显示的title”,"title");

//例如 customView.setTextViewText(R.id.titlet,""这里是标题);

NotificationCompat.Builder mBuilder=newNotificationCompat.Builder(context);

mBuilder.setContent(customView)

.setPriority(Notification.PRIORITY_DEFAULT)

.setOngoing(false)

.setSmallIcon(R.mipmap.ic_launcher);

Notification notify=mBuilder.build();

notify.bigContentView=customView;

notify.flags|=Notification.FLAG_AUTO_CANCEL;//滑动通知后通知栏消失

//通知id需要不唯一,要不然会覆盖前一条通知

intnotifyId=(int)System.currentTimeMillis();

NotificationManager manager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

manager.notify(notifyId,notify);

}}

这里展示布局

布局这里要给定值,至于要多高自己设置

finally

一定不要忘了在配置文件中配置MyReceiver

至于怎么配置,就去推送的官网看看,我这里边的配置的是极光推送

最终 有什么问题,联系一下我 :本人微信:13993365940

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值