android开发怎么给通知栏添加点击事件
1个回答
2015-02-03
展开全部
//注册按钮广播
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);
}
);
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);
}
);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询