show a heads up notification at incoming call, not the fullscreen dialer
This commit is contained in:
parent
bf79a977bb
commit
0ec5b4b58b
5 changed files with 68 additions and 10 deletions
|
@ -18,6 +18,7 @@
|
|||
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
|
||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.telephony"
|
||||
|
@ -246,11 +247,23 @@
|
|||
|
||||
<service
|
||||
android:name=".services.MyIncomingCallService"
|
||||
android:directBootAware="true"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_INCALL_SERVICE">
|
||||
|
||||
<meta-data
|
||||
android:name="android.telecom.IN_CALL_SERVICE_UI"
|
||||
android:value="true"/>
|
||||
|
||||
<meta-data
|
||||
android:name="android.telecom.IN_CALL_SERVICE_RINGING"
|
||||
android:value="false"/>
|
||||
|
||||
<meta-data
|
||||
android:name="android.telecom.INCLUDE_EXTERNAL_CALLS"
|
||||
android:value="true"/>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.telecom.InCallService"/>
|
||||
</intent-filter>
|
||||
|
@ -260,9 +273,8 @@
|
|||
android:name=".services.MyOutgoingCallService"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.telecomm.ConnectionService"/>
|
||||
<action android:name="android.telecom.ConnectionService"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue