show a heads up notification at incoming call, not the fullscreen dialer

This commit is contained in:
tibbi
2018-11-22 23:18:36 +01:00
parent bf79a977bb
commit 0ec5b4b58b
5 changed files with 68 additions and 10 deletions

View File

@ -0,0 +1,33 @@
package com.simplemobiletools.contacts.pro.helpers
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.telecom.Connection
import android.telecom.DisconnectCause
@TargetApi(Build.VERSION_CODES.M)
class MyConnection(val context: Context) : Connection() {
override fun onAnswer() {
super.onAnswer()
setActive()
}
override fun onReject() {
super.onReject()
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
destroy()
}
override fun onAbort() {
super.onAbort()
setDisconnected(DisconnectCause(DisconnectCause.REMOTE))
destroy()
}
override fun onDisconnect() {
super.onDisconnect()
setDisconnected(DisconnectCause(DisconnectCause.CANCELED))
destroy()
}
}

View File

@ -47,7 +47,7 @@ class DialerCallService : Service() {
if (isOreoPlus()) {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val name = resources.getString(R.string.app_name)
val importance = NotificationManager.IMPORTANCE_LOW
val importance = NotificationManager.IMPORTANCE_HIGH
NotificationChannel(channelId, name, importance).apply {
enableLights(false)
enableVibration(false)

View File

@ -6,11 +6,10 @@ import android.os.Build
import android.telecom.Call
import android.telecom.InCallService
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.simplemobiletools.contacts.pro.activities.DialerActivity
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.INCOMING_CALL
import com.simplemobiletools.contacts.pro.helpers.IS_INCOMING_CALL
import com.simplemobiletools.contacts.pro.objects.CallManager
@TargetApi(Build.VERSION_CODES.M)
@ -27,12 +26,13 @@ class MyIncomingCallService : InCallService() {
handle
}
Intent(this, DialerActivity::class.java).apply {
action = INCOMING_CALL
Intent(this, DialerCallService::class.java).apply {
putExtra(CALL_STATUS, call.state)
putExtra(CALL_NUMBER, callerNumber)
startActivity(this)
putExtra(IS_INCOMING_CALL, true)
startService(this)
}
CallManager.updateCall(call)
}
@ -46,6 +46,11 @@ class MyIncomingCallService : InCallService() {
override fun onStateChanged(call: Call, state: Int) {
CallManager.updateCall(call)
sendCallToActivity(call)
if (state == Call.STATE_DISCONNECTED) {
Intent(applicationContext, DialerCallService::class.java).apply {
stopService(this)
}
}
}
}

View File

@ -1,10 +1,18 @@
package com.simplemobiletools.contacts.pro.services
import android.annotation.TargetApi
import android.net.Uri
import android.os.Build
import android.telecom.ConnectionService
import android.telecom.*
import com.simplemobiletools.contacts.pro.helpers.MyConnection
@TargetApi(Build.VERSION_CODES.M)
class MyOutgoingCallService : ConnectionService() {
override fun onCreateIncomingConnection(connectionManagerPhoneAccount: PhoneAccountHandle, request: ConnectionRequest): Connection {
val connection = MyConnection(applicationContext)
val phoneNumber = request.extras.get(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS) as Uri
connection.setAddress(phoneNumber, TelecomManager.PRESENTATION_ALLOWED)
connection.setRinging()
return connection
}
}