title: android.app.RemoteServiceException: Bad notification for startForeground when trying to send notification from a service
body: <p>I have looked at all the SO posts related to this error, that I could find on Google. Most of them were about the requirement to add CHANNEL_ID in Android 8. Others were due to missing pieces of code, that I think are fixed in mine.</p>
  <p>I have referred <a href="https://developer.android.com/training/notify-user/time-sensitive" rel="nofollow noreferrer">this</a> article, and tried implementing the same. I am looking to send a Full Screen Intent notification.</p>
  <p>Notifier.java</p>
  <pre class="lang-java prettyprint-override"><code>public class Notifier extends Service {
      @Override
      public void onCreate() {
          super.onCreate();
          Context context = this;
  
          Intent fullScreenIntent = new Intent(context, CamView.class);
          PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(context, 0,
                  fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
          CharSequence name = getString(R.string.channel_name);
          String description = getString(R.string.channel_description);
          int importance = NotificationManager.IMPORTANCE_HIGH;
          NotificationChannel doorBellChannel = new NotificationChannel(getString(R.string.channel_name), name, importance);
          doorBellChannel.setDescription(description);
          NotificationManager notificationManager = getSystemService(NotificationManager.class);
          notificationManager.createNotificationChannel(doorBellChannel);
  
  
  
          NotificationCompat.Builder notificationBuilder =
                  new NotificationCompat.Builder(context, String.valueOf(R.string.channel_name))
                          //.setChannelId(String.valueOf(R.string.channel_name))
                          .setSmallIcon(R.drawable.ic_launcher_foreground)
                          .setContentTitle(&quot;Incoming call&quot;)
                          .setContentText(&quot;(919) 555-1234&quot;)
                          .setPriority(NotificationCompat.PRIORITY_MAX)
                          .setCategory(NotificationCompat.CATEGORY_CALL)
                          .setChannelId(String.valueOf(R.string.channel_name))
                          .setFullScreenIntent(fullScreenPendingIntent, true)
                          .setAutoCancel(true);
  
  
  
  
          Notification incomingCallNotification = notificationBuilder.build();
  
          Log.d(TAG, &quot;onCreate: Here 1&quot;);
  
          int notificationId = createID();
          startForeground(notificationId, incomingCallNotification);
  
  
          Log.d(TAG, &quot;onCreate: Here 2&quot;);
  
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
  
  
          return super.onStartCommand(intent, flags, startId);
      }
  
      public int createID(){
          Date now = new Date();
          return Integer.parseInt(new SimpleDateFormat(&quot;ddHHmmss&quot;,  Locale.US).format(now));
      }
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }
  </code></pre>
  <p>I have these 2 lines in the AndroidManifest.xml:</p>
  <pre class="lang-xml prettyprint-override"><code>    &lt;uses-permission android:name=&quot;android.permission.USE_FULL_SCREEN_INTENT&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.FOREGROUND_SERVICE&quot;/&gt;
  </code></pre>
  <p>When the service is called, I get the following error:</p>
  <pre><code>2021-06-11 17:17:27.213 9432-9432/? D/Oscillator: onCreate: Here 1
  2021-06-11 17:17:27.231 9432-9432/? D/Oscillator: onCreate: Here 2
  2021-06-11 17:17:27.240 9432-9432/? D/AndroidRuntime: Shutting down VM
  2021-06-11 17:17:27.242 9432-9432/? E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.smartlock, PID: 9432
      android.app.RemoteServiceException: Bad notification for startForeground
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1946)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:214)
          at android.app.ActivityThread.main(ActivityThread.java:7397)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
  2021-06-11 17:17:27.260 9432-9432/? I/Process: Sending signal. PID: 9432 SIG: 9
  </code></pre>