我正在研究VOIP应用程序,最近遇到了一个问题。当屏幕锁定且应用程序处于后台时,某些设备无法唤醒。我做了一些测试,发现:
所以,我想这与主页按钮或屏幕锁定时应用程序处于后台这一事实有关。当收到Firebase消息或JNI触发了一些回调时,应用程序将调用startActivity()
这是我解锁屏幕的方式:
if (powerManager != null) {
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "App:wakeuptag");
wakeLock.acquire(1000 * 60);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
setTurnScreenOn(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}
这是我开始活动的方式:
Intent intent = new Intent(context, VCEngine.appInfo().getActivity(ActivityType.CALL));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mIsCallFromBackground.set(!AppUtils.isAppOnForeground());
}
intent.putExtra(
context.getString(R.string.extra_conference_join_or_create),
msg);
intent.putExtra(context.getString(R.string.extra_is_audio_call), isAudioCall);
intent.putExtra("isConference", isConference());
context.startActivity(intent);