Android 10-当应用程序处于后台和锁定屏幕时,活动未打开
我正在处理呼叫应用程序,在One plus设备(Android 10)中,当我使用twilio从一个用户向另一个用户进行呼叫时,当应用程序处于后台时,我收到来电通知,然后我使用来电活动启动来电屏幕,但在One plus中,它不工作。在安卓10以下的其他设备中,它正在工作Android 10-当应用程序处于后台和锁定屏幕时,活动未打开,android,push-notification,background,firebase-cloud-messaging,twilio-programmable-voice,Android,Push Notification,Background,Firebase Cloud Messaging,Twilio Programmable Voice,我正在处理呼叫应用程序,在One plus设备(Android 10)中,当我使用twilio从一个用户向另一个用户进行呼叫时,当应用程序处于后台时,我收到来电通知,然后我使用来电活动启动来电屏幕,但在One plus中,它不工作。在安卓10以下的其他设备中,它正在工作 @Override public void onMessageReceived(final RemoteMessage remoteMessage) { Intent intent = new Intent(this,
@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" />
Window-Window=this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG\u打开屏幕
|WindowManager.LayoutParams.FLAG_锁定时显示
|WindowManager.LayoutParams.FLAG\u保持屏幕\u打开
|WindowManager.LayoutParams.FLAG_discover_KEYGUARD);
您需要使用包含您的活动的挂起内容调用通知。
我从这里得到了密码:
看起来他称之为startforeground和StartTactivity。
在我的应用程序中,我的活动被调用了两次,因此我只调用startforeground,但两次调用后警报工作正常。我在中回答了相同的问题。也许这会对你有所帮助。@MuhammadFarhan我知道你的答案。我收到通知,当我点击该通知时,我的呼叫屏幕打开。但同时,什么样的应用程序能够在不点击通知的情况下打开屏幕?因此,当您收到通知时,您的应用程序不会唤醒设备?当收到通知时,设备会唤醒,但不会打开屏幕。在Android 10中,当应用程序处于锁定模式时,时间敏感通知对我有效。在我重新安装应用程序后,它可以工作。链接不再有效:(谢谢,我更新了它,现在又可以工作了。)
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);