Skip to content

Commit

Permalink
Merge pull request #417 from hiennguyen92/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hiennguyen92 committed Jan 5, 2024
2 parents 1afaee1 + c319c8e commit b4bf95a
Show file tree
Hide file tree
Showing 34 changed files with 1,254 additions and 171 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2.0.1

* Fixed some bugs.
* `Android` using Telecom Framework
* Add `silenceEvents`
* Add `normalHandle` props https://github.com/hiennguyen92/flutter_callkit_incoming/pull/403
* Android add `textColor` props https://github.com/hiennguyen92/flutter_callkit_incoming/pull/398
* Android invisible avatar for default https://github.com/hiennguyen92/flutter_callkit_incoming/pull/393
* Add Method for call API when accept/decline/end/timeout

## 2.0.0+2

* Fixed some bugs.
Expand Down
93 changes: 82 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
```
<manifest...>
...
<!--
<!--
Using for load image from internet
-->
<uses-permission android:name="android.permission.INTERNET"/>
Expand All @@ -65,7 +65,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
* Import
```console
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
```
```
* Received an incoming call
```dart
this._currentUuid = _uuid.v4();
Expand Down Expand Up @@ -94,6 +94,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
backgroundColor: '#0955fa',
backgroundUrl: 'https://i.pravatar.cc/500',
actionColor: '#4CAF50',
textColor: '#ffffff',
incomingCallNotificationChannelName: "Incoming Call",
missedCallNotificationChannelName: "Missed Call"
),
Expand Down Expand Up @@ -194,7 +195,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca

//Example
d6a77ca80c5f09f87f353cdd328ec8d7d34e92eb108d046c91906f27f54949cd

```
Make sure using `SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP(deviceToken)` inside AppDelegate.swift (<a href="https://github.com/hiennguyen92/flutter_callkit_incoming/blob/master/example/ios/Runner/AppDelegate.swift">Example</a>)
```swift
Expand All @@ -204,7 +205,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
//Save deviceToken to your server
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP(deviceToken)
}

func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
print("didInvalidatePushTokenFor")
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP("")
Expand Down Expand Up @@ -263,7 +264,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
}
});
```
* Call from Native (iOS/Android)
* Call from Native (iOS/Android)

```swift
//Swift iOS
Expand All @@ -274,12 +275,12 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
info["type"] = 1
//... set more data
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(flutter_callkit_incoming.Data(args: info), fromPushKit: true)

//please make sure call `completion()` at the end of the pushRegistry(......, completion: @escaping () -> Void)
// or `DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { completion() }`
// if you don't call completion() in pushRegistry(......, completion: @escaping () -> Void), there may be app crash by system when receiving voIP
```

```kotlin
//Kotlin/Java Android
FlutterCallkitIncomingPlugin.getInstance().showIncomingNotification(...)
Expand All @@ -295,7 +296,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
//... set more data
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(data, fromPushKit: true)
```

<br>

```objc
Expand All @@ -312,7 +313,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
//... set more data
[SwiftFlutterCallkitIncomingPlugin.sharedInstance showCallkitIncoming:data fromPushKit:YES];
```

<br>

```swift
Expand All @@ -325,6 +326,75 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
//Kotlin/Java Android
FlutterCallkitIncomingPlugin.getInstance().sendEventCustom(body: Map<String, Any>)
```
* 3.1 Call API when accept/decline/end/timeout
```swift
//Appdelegate
...
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate, CallkitIncomingAppDelegate {
...

// Func Call api for Accept
func onAccept(_ call: Call) {
let json = ["action": "ACCEPT", "data": call.data.toJSON()] as [String: Any]
print("LOG: onAccept")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")

case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
}
// Func Call API for Decline
func onDecline(_ call: Call) {
let json = ["action": "DECLINE", "data": call.data.toJSON()] as [String: Any]
print("LOG: onDecline")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")

case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
}
func onEnd(_ call: Call) {
let json = ["action": "END", "data": call.data.toJSON()] as [String: Any]
print("LOG: onEnd")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")

case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
}
func onTimeOut(_ call: Call) {
let json = ["action": "TIMEOUT", "data": call.data.toJSON()] as [String: Any]
print("LOG: onTimeOut")
self.performRequest(parameters: json) { result in
switch result {
case .success(let data):
print("Received data: \(data)")

case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
}
...

```
<a href='https://github.com/hiennguyen92/flutter_callkit_incoming/blob/master/example/ios/Runner/AppDelegate.swift'>Please check full: Example</a>

4. Properties

Expand Down Expand Up @@ -366,11 +436,12 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
| **`backgroundColor`** | Incoming call screen background color. | `#0955fa` |
| **`backgroundUrl`** | Using image background for Incoming call screen. example: http://... https://... or "assets/abc.png" | _None_ |
| **`actionColor`** | Color used in button/text on notification. | `#4CAF50` |
| **`textColor`** | Color used for the text in full screen notification. | `#ffffff` |
| **`incomingCallNotificationChannelName`** | Notification channel name of incoming call. | `Incoming call` |
| **`missedCallNotificationChannelName`** | Notification channel name of missed call. | `Missed call` |

<br>

* iOS

| Prop | Description | Default |
Expand Down Expand Up @@ -415,7 +486,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca

## :bulb: Demo

1. Demo Illustration:
1. Demo Illustration:
2. Image
<table>
<tr>
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>

<application>

Expand Down Expand Up @@ -48,5 +49,15 @@
android:exported="true"
android:name="com.hiennv.flutter_callkit_incoming.CallkitSoundPlayerService"/>

<service
android:enabled="true"
android:exported="true"
android:name="com.hiennv.flutter_callkit_incoming.telecom.TelecomConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ data class Data(val args: Map<String, Any?>) {
var backgroundColor: String
@JsonProperty("backgroundUrl")
var backgroundUrl: String
@JsonProperty("textColor")
var textColor: String
@JsonProperty("actionColor")
var actionColor: String
@JsonProperty("incomingCallNotificationChannelName")
Expand All @@ -71,6 +73,13 @@ data class Data(val args: Map<String, Any?>) {
@JsonProperty("isAccepted")
var isAccepted: Boolean = false

@JsonProperty("isOnHold")
var isOnHold: Boolean = (args["isOnHold"] as? Boolean) ?: false
@JsonProperty("audioRoute")
var audioRoute: Int = (args["audioRoute"] as? Int) ?: 1
@JsonProperty("isMuted")
var isMuted: Boolean = (args["isMuted"] as? Boolean) ?: false

init {
var android: Map<String, Any?>? = args["android"] as? HashMap<String, Any?>?
android = android ?: args
Expand All @@ -81,6 +90,7 @@ data class Data(val args: Map<String, Any?>) {
backgroundColor = android["backgroundColor"] as? String ?: "#0955fa"
backgroundUrl = android["backgroundUrl"] as? String ?: ""
actionColor = android["actionColor"] as? String ?: "#4CAF50"
textColor = android["textColor"] as? String ?: "#ffffff"
incomingCallNotificationChannelName =
android["incomingCallNotificationChannelName"] as? String
missedCallNotificationChannelName = android["missedCallNotificationChannelName"] as? String
Expand Down Expand Up @@ -178,6 +188,7 @@ data class Data(val args: Map<String, Any?>) {
CallkitConstants.EXTRA_CALLKIT_BACKGROUND_URL,
backgroundUrl
)
bundle.putString(CallkitConstants.EXTRA_CALLKIT_TEXT_COLOR, textColor)
bundle.putString(CallkitConstants.EXTRA_CALLKIT_ACTION_COLOR, actionColor)
bundle.putString(CallkitConstants.EXTRA_CALLKIT_ACTION_FROM, from)
bundle.putString(
Expand Down Expand Up @@ -256,6 +267,10 @@ data class Data(val args: Map<String, Any?>) {
CallkitConstants.EXTRA_CALLKIT_ACTION_COLOR,
"#4CAF50"
)
data.textColor = bundle.getString(
CallkitConstants.EXTRA_CALLKIT_TEXT_COLOR,
"#FFFFFF"
)
data.from =
bundle.getString(CallkitConstants.EXTRA_CALLKIT_ACTION_FROM, "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ object CallkitConstants {
"com.hiennv.flutter_callkit_incoming.ACTION_CALL_CALLBACK"
const val ACTION_CALL_CUSTOM =
"com.hiennv.flutter_callkit_incoming.ACTION_CALL_CUSTOM"
const val ACTION_CALL_AUDIO_STATE_CHANGE = "com.hiennv.flutter_callkit_incoming.ACTION_CALL_AUDIO_STATE_CHANGE"
const val ACTION_CALL_HELD = "com.hiennv.flutter_callkit_incoming.ACTION_CALL_HELD"
const val ACTION_CALL_UNHELD = "com.hiennv.flutter_callkit_incoming.ACTION_CALL_UNHELD"


const val EXTRA_CALLKIT_INCOMING_DATA = "EXTRA_CALLKIT_INCOMING_DATA"
Expand Down Expand Up @@ -52,10 +55,11 @@ object CallkitConstants {
const val EXTRA_CALLKIT_BACKGROUND_COLOR = "EXTRA_CALLKIT_BACKGROUND_COLOR"
const val EXTRA_CALLKIT_BACKGROUND_URL = "EXTRA_CALLKIT_BACKGROUND_URL"
const val EXTRA_CALLKIT_ACTION_COLOR = "EXTRA_CALLKIT_ACTION_COLOR"
const val EXTRA_CALLKIT_TEXT_COLOR = "EXTRA_CALLKIT_TEXT_COLOR"
const val EXTRA_CALLKIT_INCOMING_CALL_NOTIFICATION_CHANNEL_NAME =
"EXTRA_CALLKIT_INCOMING_CALL_NOTIFICATION_CHANNEL_NAME"
const val EXTRA_CALLKIT_MISSED_CALL_NOTIFICATION_CHANNEL_NAME =
"EXTRA_CALLKIT_MISSED_CALL_NOTIFICATION_CHANNEL_NAME"

const val EXTRA_CALLKIT_ACTION_FROM = "EXTRA_CALLKIT_ACTION_FROM"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ class CallkitIncomingActivity : Activity() {
val data = intent.extras?.getBundle(CallkitConstants.EXTRA_CALLKIT_INCOMING_DATA)
if (data == null) finish()

val textColor = data?.getString(CallkitConstants.EXTRA_CALLKIT_TEXT_COLOR, "#ffffff")
tvNameCaller.text = data?.getString(CallkitConstants.EXTRA_CALLKIT_NAME_CALLER, "")
tvNumber.text = data?.getString(CallkitConstants.EXTRA_CALLKIT_HANDLE, "")

try {
tvNameCaller.setTextColor(Color.parseColor(textColor))
tvNumber.setTextColor(Color.parseColor(textColor))
} catch (error: Exception) {
}

val isShowLogo = data?.getBoolean(CallkitConstants.EXTRA_CALLKIT_IS_SHOW_LOGO, false)
ivLogo.visibility = if (isShowLogo == true) View.VISIBLE else View.INVISIBLE

Expand Down Expand Up @@ -197,6 +204,12 @@ class CallkitIncomingActivity : Activity() {
val textDecline = data?.getString(CallkitConstants.EXTRA_CALLKIT_TEXT_DECLINE, "")
tvDecline.text = if (TextUtils.isEmpty(textDecline)) getString(R.string.text_decline) else textDecline

try {
tvAccept.setTextColor(Color.parseColor(textColor))
tvDecline.setTextColor(Color.parseColor(textColor))
} catch (error: Exception) {
}

val backgroundColor = data?.getString(CallkitConstants.EXTRA_CALLKIT_BACKGROUND_COLOR, "#0955fa")
try {
ivBackground.setBackgroundColor(Color.parseColor(backgroundColor))
Expand Down

0 comments on commit b4bf95a

Please sign in to comment.