android 通知 可横幅展示的哦

找了好多个资源都不能横幅展示用,终于弄出来了!老铁们记得开启通知横幅权限。

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notifyBuilder =
                new NotificationCompat.Builder( this ).setContentTitle( "title" )
                        .setContentText( "ContentText" )
                        .setSmallIcon( R.drawable.icon )
                        // 点击消失
                        .setAutoCancel( true )
                        // 设置该通知优先级
                        .setPriority( Notification.PRIORITY_MAX )
                        .setLargeIcon( BitmapFactory.decodeResource( this.getResources(), R.drawable.icon ) )
//                        .setTicker( mTicker )
                        // 通知首次出现在通知栏,带上升动画效果的
                        .setWhen( System.currentTimeMillis() )
                        // 通知产生的时间,会在通知信息里显示
                        // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
                        .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND );
        Intent XuanIntent = new Intent();
        XuanIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        XuanIntent.setClass(this, MainActivity.class);
        PendingIntent resultPendingIntent =
                PendingIntent.getActivity( this, 0, XuanIntent, PendingIntent.FLAG_UPDATE_CURRENT );
        notifyBuilder.setContentIntent( resultPendingIntent );
        mNotificationManager.notify( 0, notifyBuilder.build() );

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值