title: Android 10 Incoming call notification like whats app when we are in another app
body: <p>Once we received FCM push notification message in android 10 background start activities restricted. Need a solution like WhatsApp and Skype notification incoming call when we are in another app.</p>
  
  <p><a href="https://i.stack.imgur.com/lfTJ8.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/lfTJ8.jpg" alt="enter image description here"></a></p>
  
  <pre><code>int NOTIFICATIONID = 1234;
         // Uri sound =  RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.capv_callingtone);
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
              NotificationManager notificationManager =
                      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
              AudioAttributes audioAttributes = new AudioAttributes.Builder()
                      .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                      .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                      .build();
              String CHANNEL_ID = BuildConfig.APPLICATION_ID.concat("_notification_id");
              String CHANNEL_NAME = BuildConfig.APPLICATION_ID.concat("_notification_name");
              assert notificationManager != null;
  
              NotificationChannel mChannel = notificationManager.getNotificationChannel(CHANNEL_ID);
              if (mChannel == null) {
                  mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
                  mChannel.setSound(sound, audioAttributes);
                  notificationManager.createNotificationChannel(mChannel);
              }
              in.setClass(CapVFirebaseMessagingService.this, DashBoardActivity.class);
              in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
              in.putExtra(NOTIFICATION_ID, NOTIFICATIONID);
              Intent buttonIntent = new Intent(getBaseContext(), NotificationReceiver.class);
              buttonIntent.putExtra(NOTIFICATION_ID, NOTIFICATIONID);
              buttonIntent.putExtra(CapV.MESSAGE_TYPE,in.getSerializableExtra(CapV.MESSAGE_TYPE));
              Log.d("Audiotask",""+in.getSerializableExtra(CapV.MESSAGE_TYPE));
              PendingIntent dismissIntent = PendingIntent.getBroadcast(getBaseContext(), 0, buttonIntent, 0);
              SharedPreferences localPrefs = getSharedPreferences(LOCAL_PREFERENCES,MODE_PRIVATE);
              SharedPreferences.Editor editor = getSharedPreferences(LOCAL_PREFERENCES, MODE_PRIVATE).edit();
              editor.putBoolean("Fragment_created",true).commit();
              editor.putBoolean("Incoming_call",true).commit();
              // The PendingIntent to launch activity.
              PendingIntent activityPendingIntent = PendingIntent.getActivity(this, 0,
                      in, 0);
              NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
  
              builder.setSmallIcon(R.drawable.logo)
                      .setContentTitle(("Incoming Call"))
                      .setContentText("Group")
                      .setDefaults(0)
                      .addAction(R.drawable.answer, getString(R.string.answer),
                              activityPendingIntent)
                      .addAction(R.drawable.reject, getString(R.string.reject),
                              dismissIntent)
                      .setPriority(NotificationCompat.PRIORITY_MAX)
                      .setCategory(NotificationCompat.CATEGORY_CALL)
                      .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                      .setSound(sound)
                      .setOngoing(true);
              android.app.Notification notification = builder.build();
              notificationManager.notify(1234, notification);
  </code></pre>
  
  <p>Any help will be highly appreciated.</p>
  
  <p>below code for foreground service and a time-sensitive notification.</p>
  
  <p>startForeground(1234, getNotification(incomingCallIntent));</p>
  
  <pre><code>private android.app.Notification getNotification(Intent in) {
  
  
  
      in.putExtra(EXTRA_STARTED_FROM_NOTIFICATION, true);
  
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,in, PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"")
              .setSmallIcon(R.drawable.logo)
              .setAutoCancel(true)
              .setPriority(NotificationCompat.PRIORITY_HIGH)
              .setFullScreenIntent(pendingIntent, true);
  
      // Set the Channel ID for Android O.
          //builder.setChannelId("115"); // Channel ID
  
     return builder.build();
  
  
  }
  </code></pre>