当前位置:   article > 正文

安卓9.0通知推送_notification.setchannelid

notification.setchannelid
  1. public void createNotificationChannel(Context context, int notifactionId) {
  2. NotificationManager notificationManager =
  3. (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  4. Notification.Builder notification = null;
  5. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  6. String channelId = String.valueOf(notifactionId);
  7. CharSequence channelName = "channelName";
  8. String channelDescription = "channelDescription";
  9. int channelImportance = NotificationManager.IMPORTANCE_DEFAULT;
  10. NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, channelImportance);
  11. // 设置描述 最长30字符
  12. notificationChannel.setDescription(channelDescription);
  13. // 该渠道的通知是否使用震动
  14. notificationChannel.enableVibration(true);
  15. // 设置显示模式
  16. notificationChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_SECRET);
  17. notificationChannel.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.order_tishi), null);
  18. notificationManager.createNotificationChannel(notificationChannel);
  19. notification = new Notification.Builder(context);
  20. notification.setChannelId(channelId);
  21. notification.setContentTitle("活动");
  22. notification.setContentText("您有一项新活动");
  23. notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.order_tishi));
  24. notification.setSmallIcon(R.mipmap.ic_launcher_round).build();
  25. } else {
  26. notification = new Notification.Builder(context);
  27. notification.setAutoCancel(true)
  28. .setContentText("自定义推送声音111")
  29. .setContentTitle("111")
  30. .setSmallIcon(R.drawable.ic_launcher)
  31. .setDefaults(Notification.DEFAULT_ALL);
  32. notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.order_tishi));
  33. }
  34. notificationManager.notify(1024, notification.getNotification());
  35. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/111466?site
推荐阅读
相关标签
  

闽ICP备14008679号