Search code examples
androidsinch

Start Activity in Lock Screen on Marshmallow or Higher devices


I'm creating a calling app with sinch service. For Incoming calls, I need to unlock the lockscreen programatically. Using flags I solved this, but its not working on Nougat.

my current code in activity:

  @Override
protected void onStart() {
    super.onStart();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);    }

and on manifest:

<activity
    android:name="IncomingCallScreenActivity"
    android:noHistory="true"
    android:showOnLockScreen="true"
    android:screenOrientation="sensorPortrait">          
</activity>

Update:

Problem is solved. I edited in the manifest:

<activity
android:name="IncomingCallScreenActivity">
</activity>    

Solution

  • I also used sinch service. For Incoming call, i solved this problem .I hope your problem can be solved by trying this:

    1.Replace

     <activity
       android:name="IncomingCallScreenActivity"
       android:noHistory="true"
       android:showOnLockScreen="true"
       android:screenOrientation="sensorPortrait">         
    </activity>
    

    By

    <activity 
       android:name="IncomingCallScreenActivity"> 
    </activity>
    

    2.Code on onCreate() in your activity:

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);    }