我正在开发通话应用程序,在One plus设备(Android 10)中,当我使用twilio从一个用户向另一个用户进行通话时,我会在应用程序处于后台时收到来电通知,然后使用来电活动启动来电屏幕,但在One plus中,它不起作用。在Android10以下的其他设备上,它也能正常工作。
@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" />
您需要调用包含您的活动的悬而未决的通知。我从这里得到了代码:kraigsandroid警报
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和StartTactivity。在我的应用程序中,我的活动被调用了两次,所以我只调用startforeground,但两次调用后,闹钟工作正常。
在应用程序处于活动状态时,调用DidReceiveEmotentification方法,当应用程序处于后台和非活动状态时,不调用DidReceiveEmotentification方法。 代码:- Func应用程序(_应用程序:UIApplication,didReceiveRemote teNotify userInfo:[AnyHasable:任何],fetchCompletionHandle
仅当打开应用并执行通知单击时,通知单击才会启动指定的活动。如果应用程序处于后台/未运行,并且执行了通知单击,则会打开应用程序的 MainActivity。简而言之,这就像应用程序在活动堆栈之后正常打开,而不是在 PendingIntent 中打开指定的活动。 我想根据它们的类型将通知单击重定向到两个不同的活动(批准详细活动和对话详细活动)。 我使用FCM进行推送通知。我在这里粘贴我的Manifes
杀死应用程序并发送推送,它正在重定向到所需的活动后,处理这个推送,把应用程序放在后台并发送推送。它将恢复最后一个活动,但意向性附加为NULL。
我可以通过firebase FCM打开活动,但这只适用于android