问问各路大神。。
通知栏点击的事件或者监听是怎么执行的?有没有具体的方法或者监听器什么的?
小弟想做一个功能是在点击通知栏的消息后打开手机中的某个文件,怎么实现呢?
一下是小弟自己的代码,还有个问题是怎么设置成点击了消息之后通知自动消失呢?
public void sendNotification(View view) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(android.R.drawable.sym_action_call);
mBuilder.setContentTitle(title.getText().toString());
mBuilder.setContentText(content.getText().toString());
Intent intent = new Intent(this, NotificationActivity.class);
// 传值
Bundle bundle = new Bundle();
bundle.putString("title", title.getText().toString());
bundle.putString("content", content.getText().toString());
intent.putExtras(bundle);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(NotificationActivity.class);
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// 按下通知栏按钮之后跳转页面
mBuilder.setContentIntent(resultPendingIntent);
// 通知管理器
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 利用notify方法发送通知
nm.notify(1, mBuilder.build());
}
------解决方案--------------------
Notification notifation = mBuilder.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(1,notifation );