android通知栏点击
① android开发怎么给通知栏添加点击事件
//注册按钮广播
private void setButtonBroadCast(){
final String STATUS_BAR_COVER_CLICK_ACTION="download";
getDownNotification().contentView.setViewVisibility(R.id.downloadCancle,View.VISIBLE);
BroadcastReceiver onClickReceiver = new BroadcastReceiver() {
private boolean flag = false;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(STATUS_BAR_COVER_CLICK_ACTION)) {
//在这里处理点击事件
interceptFlag= true;
//取消通知栏
}
}};
IntentFilter filter = new IntentFilter();
filter.addAction(STATUS_BAR_COVER_CLICK_ACTION);
mContext.registerReceiver(onClickReceiver, filter);
Intent buttonIntent = new Intent(STATUS_BAR_COVER_CLICK_ACTION);
PendingIntent pendButtonIntent = PendingIntent.getBroadcast(mContext, 0, buttonIntent, 0);
getDownNotification().contentView.setOnClickPendingIntent(R.id.downloadCancle, pendButtonIntent);
//R.id.trackname为你要监听按钮的id
// mRemoteViews.setOnClickPendingIntent(R.id.trackname, pendButtonIntent);
}
);
② 【Android】Notification通知栏使用RemoteViews自定义布局,怎么自定义点击事件
首先你的自定义布局的Notification是不是有一个RemoteView,那你就可以通过这个RemoteView来设置点击事件:
mRemoteViews.setOnClickPendingIntent(R.id.xxx, mPendingIntent);
其中你的R.id.xxx 就是你那个被点击的控件的id
mPendingIntent是一个PendingIntent,它可以这样定义:
mPendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
注意到里面需要一个参数intent:
Intent intent = new Intent(xxx ,AaaActivity);
这样当点击时,就可以跳转到AaaActivity
③ android的通知栏是怎么响应点击图标的事件的
这个notification一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以并处理这个快讯。 状态栏和状态条的区别: 1、状态条就是手机屏幕最上方的一个条形状的区域; 在状态条有好多信息量:比如usb连接图标,手机信号图标,电池电量图标,时间图标等等; 2、状态栏就是手从状态条滑下来的可以伸缩的view; 在状态栏中一般有两类(使用FLAG_标记): (1)正在进行的程序; (2)是通知事件; 快速创建一个Notification的步骤简单可以分为以下四步: 通过getSystemService()方法得到NotificationManager对象; 对Notification的一些属性进行设置比如:内容,图标,标题,相应notification的动作进行处理等等; 通过NotificationManager对象的notify()方法来执行一个notification的消息; 通过NotificationManager对象的cancel()方法来取消一个notificatioin的消息; 关于Notification的Flags notification.flags = Notification.FLAG_NO_CLEAR; // 点击清除按钮时就会清除消息通知,但是点击通知栏的通知时不会消失 notification.flags = Notification.FLAG_ONGOING_EVENT; // 点击清除按钮不会清除消息通知,可以用来表示在正在运行 notification.flags = Notification.FLAG_AUTO_CANCEL; // 点击清除按钮或点击通知后会自动消失 notification.flags = Notification.FLAG_INSISTENT; // 一直进行,比如音乐一直播放,知道用户响应
④ android 怎么让通知栏点击后不消失 但可以被按钮清除
android 让通知栏点击后不消失 但可以被按钮清除,可以这样做:
APP发送通知时,通知需要添加flag:
Notification notification;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
或者
notification.flags |= Notification.FLAG_NO_CLEAR;
PendingIntent.FLAG_CANCEL_CURRENT;
PendingIntent.FLAG_NO_CREATE;
PendingIntent.FLAG_ONE_SHOT;
PendingIntent.FLAG_UPDATE_CURRENT;
参考资料:http://blog.csdn.net/hknock/article/details/8465410
⑤ oppo怎么关闭android系统通知栏
通知管理可以管理所有应用的通知权限,您可以自行选择各应用通知的展开方式。
1、前往设置 > 通知与状态栏 > 通知管理。
2、选择应用 > 开启或关闭允许通知,还可以在这里选择来通知时在桌面图标上显示数字角标、圆点角标或无角标。
开启应用的通知权限后,应用的常规推送会集中展示在通知中心。
在解锁后的任意屏幕下,从屏幕顶部向下轻扫,即可看到通知中心的消息。
若通知中心里有您不感兴趣的消息,您可以通过以下两种方式删除通知:1、向左/向右滑动单个通知,出现删除图标后,点击删除图标进行删除,或继续向左滑动直接删除。
2、点击通知中心右下角全部清除,将通知一次性全部删除。
本回答适用于OPPO所有机型。
⑥ android 自定义通知栏
Notification 参数使用 参考:
http://www.cnblogs.com/kexing/p/8371051.html
自定义通知栏
仅支持FrameLayout、LinearLayout、RelativeLayout三种布局控件
AnalogClock、Chronometer、Button、ImageButton、ImageView、ProgressBar、TextView、ViewFlipper、ListView、GridView、StackView和AdapterViewFlipper这些显示控件
否则会引起ClassNotFoundException异常。
流程:点击通知栏 发送广播 app接收广播做相应处理:
为通知栏绑定广播事件:
1.FLAG_CANCEL_CURRENT:如果AlarmManager管理的PendingIntent已经存在,那么将会取消当前的PendingIntent,从而创建一个新的PendingIntent.
2.FLAG_UPDATE_CURRENT:如果AlarmManager管理的PendingIntent已经存在,让新的Intent更新之前Intent对象数据,例如更新Intent中的Extras,另外,我们也可以在PendingIntent的原进程中调用PendingIntent的cancel ()把其从系统中移除掉
3.FLAG_NO_CREATE:如果AlarmManager管理的PendingIntent已经存在,那么将不进行任何操作,直接返回已经.
4.FLAG_ONE_SHOT:该PendingIntent只作用一次.在该PendingIntent对象通过send()方法触发过后,PendingIntent将自动调用cancel()进行销毁,那么如果你再调用send()方法的话,系统将会返回一个SendIntentException.
添加广播接收:
AndroidManifest: