show an incoming call screen over the lockscreen, if the screen is off

This commit is contained in:
tibbi 2018-11-28 15:19:51 +01:00
parent 4800ac3573
commit 8b3c08970c
3 changed files with 31 additions and 10 deletions

View File

@ -225,7 +225,8 @@
<activity
android:name=".activities.DialerActivity"
android:label="@string/dialer"
android:launchMode="singleTask">
android:launchMode="singleTask"
android:showOnLockScreen="true">
<intent-filter>
<action android:name="android.intent.action.CALL"/>

View File

@ -18,6 +18,7 @@ import android.os.PowerManager
import android.telecom.Call
import android.telecom.PhoneAccount
import android.telecom.TelecomManager
import android.view.WindowManager
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.contacts.pro.R
@ -48,6 +49,11 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
setContentView(R.layout.activity_dialer)
initProximityWakeLock()
LocalBroadcastManager.getInstance(applicationContext).registerReceiver(messageReceiver, IntentFilter(DIALER_INTENT_FILTER))
window.apply {
addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
val action = intent.action
val extras = intent.extras

View File

@ -1,15 +1,17 @@
package com.simplemobiletools.contacts.pro.services
import android.annotation.TargetApi
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.telecom.Call
import android.telecom.InCallService
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.simplemobiletools.contacts.pro.helpers.CALL_NUMBER
import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS
import com.simplemobiletools.contacts.pro.helpers.DIALER_INTENT_FILTER
import com.simplemobiletools.contacts.pro.helpers.IS_INCOMING_CALL
import com.simplemobiletools.contacts.pro.activities.DialerActivity
import com.simplemobiletools.contacts.pro.helpers.*
import com.simplemobiletools.contacts.pro.objects.CallManager
@TargetApi(Build.VERSION_CODES.M)
@ -25,12 +27,24 @@ class MyIncomingCallService : InCallService() {
handle
}
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (keyguardManager.isKeyguardLocked) {
Intent(this, DialerActivity::class.java).apply {
action = RESUME_DIALER
flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK
putExtra(CALL_NUMBER, callerNumber)
putExtra(CALL_STATUS, call.state)
putExtra(IS_INCOMING_CALL, true)
startActivity(this)
}
} else {
Intent(this, DialerCallService::class.java).apply {
putExtra(CALL_STATUS, call.state)
putExtra(CALL_NUMBER, callerNumber)
putExtra(IS_INCOMING_CALL, true)
startService(this)
}
}
CallManager.updateCall(call)
}