首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

notification里一个button如何绑定事件

2013-10-29 
notification里一个button怎么绑定事件notification里一个button怎么绑定事件。。。求解,项目卡着了[解决办法

notification里一个button怎么绑定事件
notification里一个button怎么绑定事件。。。求解,项目卡着了
[解决办法]
android Notification中添加一个按钮如何监听按钮事件
[解决办法]
你可以设置点击按钮后,发送一个广播,然后在你需要处理这个动作的类或者activity里监听这个广播,然后进行相应的处理。
       

// 比如有个ID为bt_cancle的按钮,点击后发送一个广播,则在创建notification时参考下面的代码添加你的按钮事件
        Intent cancelIntent = new Intent(NOTIFY_CANCEL);
        cancelIntent.putExtra(INTENT_URL, url);
        Bundle bundleCancel = new Bundle();
        bundleCancel.putInt(INTENT_FLAG, notifyflag);
        cancelIntent.putExtras(bundleCancel);
        PendingIntent cancelPendIntent = PendingIntent.getBroadcast(this, notifyflag,
                cancelIntent, 0);
        mRemoteViews.setOnClickPendingIntent(R.id.bt_cancle, cancelPendIntent);

热点排行