0

I am working on call application, In One plus devices (Android 10) When I doing call using twilio from one user to other user, I am getting notification of incoming call while app is in background and then I am starting Incoming call Screen using Incoming Activity but in One plus it is not working. In other devices below Android 10 it is working.

@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
    Intent intent = new Intent(this, IncomingCallActivity.class);
    intent.setAction(IncomingCallActivity.ACTION_INCOMING_CALL);
    intent.putExtra(IncomingCallActivity.INCOMING_CALL_NOTIFICATION_ID, notificationId);
    intent.putExtra(IncomingCallActivity.INCOMING_CALL_INVITE, callInvite);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    MyFirebaseMessagingService.this.startActivity(intent);
}

I have also tried with adding flags to activity

Window window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);


<activity
    android:name=".IncomingCallActivity"
    android:excludeFromRecents="true"
    android:noHistory="true"
    android:screenOrientation="sensorPortrait"
    android:showOnLockScreen="true"
    android:showWhenLocked="true"
    android:turnScreenOn="true" />
Nik
  • 1,991
  • 2
  • 13
  • 30
  • I have answered the same question in [here](https://stackoverflow.com/questions/58245398/how-to-start-an-activity-from-background-in-android-10/59893431#59893431). Maybe that will help you. – Muhammad Farhan Feb 03 '20 at 11:37
  • @MuhammadFarhan I am aware about your answer. I am getting notification and when I click on that notification my call screen is opening. but at same time What's app is able to open screen without clicking on notification – Nik Feb 03 '20 at 11:42
  • So yours not waking up the device when you receive the notification? – Muhammad Farhan Feb 03 '20 at 11:50
  • Device is waking up when notification received but not opening screen – Nik Feb 03 '20 at 11:56
  • https://developer.android.com/guide/components/activities/background-starts – CommonsWare Feb 03 '20 at 12:09
  • @CommonsWare What is reason that whatsapp is able to show screen? – Nik Feb 03 '20 at 12:14
  • I do not use Whatsapp, so I cannot comment on its behavior. Standard phone apps show a heads-up notification on Android 10. – CommonsWare Feb 03 '20 at 12:17
  • @CommonsWare I also checked with Google Duo. It is also working when app is in background or in lock mode – Nik Feb 03 '20 at 12:22
  • @Nik did you set ```setFullScreenIntent``` in you ***notificationBuilder*** as they suggested in [here](https://developer.android.com/training/notify-user/time-sensitive) – Muhammad Farhan Feb 03 '20 at 12:23
  • @MuhammadFarhan Yes I did that – Nik Feb 03 '20 at 12:27
  • 1
    Display time-sensitive notifications Works for me when app is in lock mode in Android 10. It works after I reinstall app. – Nik Feb 03 '20 at 13:53

1 Answers1

2

You need to call a notification with a pendingintent containing your activity. I got the code from here: kraigsandroidalarm

 Intent notify = new Intent(this, AlarmNotificationActivity.class)
  .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

final NotificationManager manager =
  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
    manager.getNotificationChannel(FIRING_ALARM_NOTIFICATION_CHAN) == null) {
  // Create a notification channel on first use.
  NotificationChannel chan = new NotificationChannel(
      FIRING_ALARM_NOTIFICATION_CHAN,
      getString(R.string.ringing_alarm_notification),
      NotificationManager.IMPORTANCE_HIGH);
  chan.setSound(null, null);  // Service manages its own sound.
  manager.createNotificationChannel(chan);
}
final Notification notification =
  (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
   new Notification.Builder(this, FIRING_ALARM_NOTIFICATION_CHAN) :
   new Notification.Builder(this))
  .setContentTitle(getString(R.string.app_name))
  .setContentText(labels.isEmpty() ? getString(R.string.dismiss) : labels)
  .setSmallIcon(R.drawable.ic_alarm_on)
  // NOTE: This takes the place of the window attribute
  // FLAG_SHOW_WHEN_LOCKED in the activity itself for newer APIs.
  .setFullScreenIntent(PendingIntent.getActivity(this, 0, notify, 0), true)
  .setCategory(Notification.CATEGORY_ALARM)
  .setPriority(Notification.PRIORITY_MAX)
  .setVisibility(Notification.VISIBILITY_PUBLIC)
  .setOngoing(true)
  .setLights(Color.WHITE, 1000, 1000)
  .build();
notification.flags |= Notification.FLAG_INSISTENT;  // Loop sound/vib/blink
startForeground(FIRING_ALARM_NOTIFICATION_ID, notification);

CountdownRefresh.stop(getApplicationContext());

// NOTE: As of API 29, this only works when the app is in the foreground.
// https://developer.android.com/guide/components/activities/background-starts
// The setFullScreenIntent option above handles the lock screen case.
startActivity(notify);

Looks that he calls startforeground and startactivity. In my application my activity is called twice, so i only call startforeground but the alarm is working well with two calls.

user3486626
  • 139
  • 1
  • 6