Android Notificationいくつかの穴


Android 0で動作する以前の正常な通知には様々な問題がある可能性があります
  • 1.通知欄が表示されない(PendingIntent.getBroadcast方式を使用)
  • 最初のステップでコードを追加するには、次の手順に従います.
     NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                String channel = AppUtil.getChannel();
                NotificationChannel mChannel = new NotificationChannel(context.getPackageName(), channel, NotificationManager.IMPORTANCE_LOW);
                notificationManager.createNotificationChannel(mChannel);
            }
            xxxxx
      builder.setChannelId(context.getPackageName());
    

    第二に、一部の機種(例えばvivio)は設定の中で対応するアプリケーションの通知スイッチを開く必要がある.
  • 2.通知欄クリック反応なしにコードを追加する必要がある:
  •  Intent broadcastIntent = new Intent(actionNAme);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                broadcastIntent.setClass(context, A.Class);
            }
    

    公式説明I ran into the same,in Android Oreo you need to make it a explicit Intent(is not enough with putting the receiver on the manifest,in fact,it won’t pay attention to that),so when you make the intent,make it explicit using the setClass method: