Android(安卓)中的通知
16lz
2022-06-05
一般手机上边都有一个状态条,显示电池电量、信号强度、未接来电、短信...Android 的屏幕上方也具有状态条。这里所说的通知,就是在这个状态条上显示通知。
发送通知的步骤如下:
1).获取通知管理器
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
2).新建一个通知,指定其图标和标题
int icon = android.R.drawable.stat_notify_chat;long when = System.currentTimeMillis();//第一个参数为图标,第二个参数为标题,第三个为通知时间Notification notification = new Notification(icon, null, when);Intent openintent = new Intent(this, OtherActivity.class);//当点击消息时就会向系统发送 openintent 意图PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openintent, 0);notification.setLatestEventInfo(this, “标题”, “内容", contentIntent);mNotificationManager.notify(0, notification);
更多相关文章
- 【Android】Android(安卓)SurfaceFlinger之BufferQueue
- Android软键盘不能正确显示
- Android控件显示和隐藏
- Android(安卓)SharedPreferences保存登录状态
- android shape的使用
- Android(安卓)Weekly Notes Issue #232
- android应用 小试牛刀 开发自己的应用程序就是这么简单
- Android(安卓)Power Management
- Android中Activity状态的保存和恢复:onSaveInstanceState和onRest