title: Android 10 java.lang.SecurityException: Not allowed to delete channel MyNotificationChannel with a foreground service
body: <p>I create a notification from a Thread:</p>
  <pre><code>final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  NotificationChannel chan = new NotificationChannel(&quot;MyNotificationChannel&quot;,&quot;Notification Title&quot;, NotificationManager.IMPORTANCE_HIGH);
  chan.setSound(null, null);
  manager.createNotificationChannel(chan);
  
  final Notification notification =
  (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O ? new Notification.Builder(context, &quot;MyNotificationChannel&quot;) : new Notification.Builder(context))
                                              .setContentTitle(context.getString(R.string.app_name))
                                              .setContentText(&quot;Text&quot;)
                                              .setSmallIcon(R.drawable.logo)
                                              .setFullScreenIntent(PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT), true)
                                              .setCategory(Notification.CATEGORY_ALARM)
                                              .setVisibility(Notification.VISIBILITY_PUBLIC)
                                              .setOngoing(true)
                                              .build();
  
  ((Service) context).startForeground(12345678, notification);
  </code></pre>
  <p>When i try to delete that notification on the ondestroy of the activity it works on most devices but on some Motorola Devices or Xiaomi with Android 10:</p>
  <pre><code>protected void onDestroy() {
    try {
  
      NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
      mNotificationManager.cancel(12345678);
      mNotificationManager.deleteNotificationChannel(&quot;MyNotificationChannel&quot;);
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  </code></pre>
  <p>This exception is through, and the notification is not delete, i try to delete in the thread and into another activities:</p>
  <pre><code>java.lang.SecurityException: Not allowed to delete channel &quot;MyNotificationChannel&quot; with a foreground service
  </code></pre>