private NotificationManager manager = null;private Notification.Builder builder = null;
private void showNotification(Context context) {    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);    builder = new Notification.Builder(context);    builder.setShowWhen(false)            .setSmallIcon(R.drawable.ic_power_low)            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_power_low))            .setContentTitle("自定义标题")            .setContentText("自定义内容")            .setDefaults(NotificationCompat.FLAG_ONGOING_EVENT)            .setPriority(Notification.PRIORITY_MAX);    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//SDK版本>=21才能设置悬挂式通知栏        builder.setCategory(String.valueOf(Notification.FLAG_ONGOING_EVENT))                .setVisibility(Notification.VISIBILITY_PUBLIC)                .setColor(context.getResources().getColor(R.color.salmon));        Intent intent = new Intent();        PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0);        builder.setFullScreenIntent(pi, true);        manager.notify(null, 0, builder.build());    }}
private void cancelNotification() {    if (manager != null) {        manager.cancel(0);    }}

更多相关文章

  1. AndClear - Android(安卓)Clean-up Management Software
  2. Android获取apk的版本及包名等信息
  3. ndk 历史版本下载
  4. Android(安卓)Q 版本新的网络状况判断方式
  5. [Android] 如何取得版本号码
  6. 高焕堂:iPhone软件是芝麻,巧用Android才能赚大钱
  7. Android(安卓)Support v4、v7、v13的区别和应用场景
  8. Cordova + vue 打包安卓(Android) apk 及 Apk版本自动升级及安装
  9. Android(安卓)更新升级版本

随机推荐

  1. 作用域、闭包,类与继承
  2. Linux运维入门教程08-01 (Linux软件包的
  3. linux-系统状态命令
  4. CRM系统如何让企业获得精确客户?
  5. k8s 高可用部署
  6. 工作多年简历是这样,老板谁敢要
  7. 4-6(容器适配器总结)
  8. 扎克伯格也中招了!超 5 亿 Facebook 用户
  9. 编写迷你版MVC小框架具体步骤以及心得体
  10. nginx配置文件