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.PROCESS_OUTGOING_CALLS"/>
|
||||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
|
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.telephony"
|
android:name="android.hardware.telephony"
|
||||||
|
@ -246,11 +247,23 @@
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.MyIncomingCallService"
|
android:name=".services.MyIncomingCallService"
|
||||||
|
android:directBootAware="true"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true"
|
||||||
android:permission="android.permission.BIND_INCALL_SERVICE">
|
android:permission="android.permission.BIND_INCALL_SERVICE">
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.telecom.IN_CALL_SERVICE_UI"
|
android:name="android.telecom.IN_CALL_SERVICE_UI"
|
||||||
android:value="true"/>
|
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>
|
<intent-filter>
|
||||||
<action android:name="android.telecom.InCallService"/>
|
<action android:name="android.telecom.InCallService"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
@ -260,9 +273,8 @@
|
||||||
android:name=".services.MyOutgoingCallService"
|
android:name=".services.MyOutgoingCallService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
|
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.telecomm.ConnectionService"/>
|
<action android:name="android.telecom.ConnectionService"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</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()) {
|
if (isOreoPlus()) {
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
val name = resources.getString(R.string.app_name)
|
val name = resources.getString(R.string.app_name)
|
||||||
val importance = NotificationManager.IMPORTANCE_LOW
|
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||||
NotificationChannel(channelId, name, importance).apply {
|
NotificationChannel(channelId, name, importance).apply {
|
||||||
enableLights(false)
|
enableLights(false)
|
||||||
enableVibration(false)
|
enableVibration(false)
|
||||||
|
|
|
@ -6,11 +6,10 @@ import android.os.Build
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.telecom.InCallService
|
import android.telecom.InCallService
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
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_NUMBER
|
||||||
import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS
|
import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS
|
||||||
import com.simplemobiletools.contacts.pro.helpers.DIALER_INTENT_FILTER
|
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
|
import com.simplemobiletools.contacts.pro.objects.CallManager
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
|
@ -27,12 +26,13 @@ class MyIncomingCallService : InCallService() {
|
||||||
handle
|
handle
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent(this, DialerActivity::class.java).apply {
|
Intent(this, DialerCallService::class.java).apply {
|
||||||
action = INCOMING_CALL
|
|
||||||
putExtra(CALL_STATUS, call.state)
|
putExtra(CALL_STATUS, call.state)
|
||||||
putExtra(CALL_NUMBER, callerNumber)
|
putExtra(CALL_NUMBER, callerNumber)
|
||||||
startActivity(this)
|
putExtra(IS_INCOMING_CALL, true)
|
||||||
|
startService(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
CallManager.updateCall(call)
|
CallManager.updateCall(call)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,11 @@ class MyIncomingCallService : InCallService() {
|
||||||
override fun onStateChanged(call: Call, state: Int) {
|
override fun onStateChanged(call: Call, state: Int) {
|
||||||
CallManager.updateCall(call)
|
CallManager.updateCall(call)
|
||||||
sendCallToActivity(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
|
package com.simplemobiletools.contacts.pro.services
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.telecom.ConnectionService
|
import android.telecom.*
|
||||||
|
import com.simplemobiletools.contacts.pro.helpers.MyConnection
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
class MyOutgoingCallService : ConnectionService() {
|
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