代码:

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);Notification notification = new Notification(icon, tickertext, System.currentTimeMillis() + 10000);// 后面的参数分别是显示在顶部通知栏的小图标,小图标旁的文字, 系统当前时间notification.defaults = Notification.DEFAULT_ALL; // 声音与震动notification.flags |= Notification.FLAG_AUTO_CANCEL; // 点击后自动消失// 这是设置通知是否同时播放声音或振动,声音为Notification.DEFAULT_SOUNDPendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, main.class), 0);// 点击通知后的动作,这里是转回main 这个Acticitynotification.setLatestEventInfo(this, title, content, pendingIntent);notificationManager.notify(notification_id, notification);

其中,
//如果是振动或者全部,必须在AndroidManifest.xml加入振动权限
<uses-permission android:name="android.permission.VIBRATE" />

更多相关文章

  1. Android 获取屏幕高宽度,密度,通知栏高度,截图等常用方法
  2. Android5.0通知变化浅析
  3. Android通知系统源码解析
  4. 系出名门Android(3) - 对话框(Dialog)和通知(Notification)
  5. Android Notification通知栏的必备姿势
  6. Android 通知(Notification)高级用法和注意事项
  7. wifi 通知栏上 选择程序时出现你的应用
  8. android之【本地通知Notification】
  9. Android 通知栏Notification 悬浮通知栏

随机推荐

  1. Android之提示Unable to instantiate fra
  2. android paint设置字体 中文字体 楷体 和
  3. android Notification 通知封装
  4. Unity android 读取文件,读取APK包文件
  5. Android第4坑:Android项目中使用lambda表
  6. Android Studio更新到3.1以后老项目跑不
  7. android handle looper 使用误区
  8. 【Android】JSON应用
  9. android客户定制SDK常见修改
  10. Android 录屏功能的实现