问题
I'm developing a VOIP
application with Qt/QML
in Android, other VOIP
applications like WhatsApp and Skype, bring up their call activities when the incoming call is received and screen is locked. I am trying to implement something like this.
I have two questions:
- What about implementing this feature completely in Java
- Implementing this feature with QML and bringing qml activity on top when the screen is locked
I have implemented a simple java call screen with window manager and WindowManager.LayoutParams.TYPE_SYSTEM_ERROR
, but i think its very platform specific and may not work in different API versions
In second case, i want to draw call screen into QML activity and show that on locked screen, but i don't know how to do it.
Could someone tell what is the correct approach for this feature and if the second one is correct, how to do it?
回答1:
If the user doesnt have high security lock i mean (Just Swipe/ none) then you can use the below code
private void turnScreenOn() {
int flags = WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
getWindow().addFlags(flags);
}
Use the above code in OnCreate of your activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
turnScreenOn();
setContentView(R.layout.alexa_alarm_actvity);
}
Remember before setContentView
Also add the permission in manifest.
android.permission.DISABLE_KEYGUARD
Best Regds
来源:https://stackoverflow.com/questions/42509119/bringing-activity-on-top-while-screen-locked