Android 10 - активность не открывается, когда приложение находится в фоновом режиме и на экране блокировки - PullRequest
0 голосов
/ 03 февраля 2020

Я работаю с приложением вызова, устройствами In One plus (Android 10). Когда я выполняю вызов с использованием twilio от одного пользователя другому, я получаю уведомление о входящем вызове, когда приложение находится в фоновом режиме, а затем я запускаю Экран входящего вызова с использованием Incoming Activity, но в One plus он не работает. В других устройствах ниже Android 10 он работает.

@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);
}

Я также пытался добавить флаги для активности

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" />

1 Ответ

0 голосов
/ 20 февраля 2020

Вам нужно вызвать уведомление с отложенным намерением, содержащее вашу активность. Я получил код отсюда: 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);

Похоже, он называет startforeground и startactivity. В моем приложении моя активность вызывается дважды, поэтому я вызываю только startforeground, но будильник работает с двумя вызовами.

...