其他常用的对话框都是显示在自己的界面上,而通知是显示在另外的应用程序的进程里的,开发的时候需要用到进程间的通信。
public void click(View v) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
"我是通知", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击通知后,自动取消显示
// 设置点击通知后的意图
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:110"));
// 延期意图
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notification.setLatestEventInfo(this, "好消息!", "您中大奖啦!", contentIntent);
nm.notify(0, notification);
}
本文介绍了如何在Android应用中实现自定义的通知,通过创建Notification并设置其样式和行为,包括使用图标、简短提示和详细信息等。同时展示了如何定义点击通知后的响应动作,如拨打电话等。
1264

被折叠的 条评论
为什么被折叠?



