Skip to content

Commit

Permalink
Merge pull request #370 from hiennguyen92/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hiennguyen92 authored Sep 25, 2023
2 parents 7777d6b + bb4c91a commit deac4f0
Show file tree
Hide file tree
Showing 16 changed files with 424 additions and 165 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0+2

* Fixed some bugs.
* Support request permission for Android 13+ `requestNotificationPermission`

## 2.0.0+1

* Fixed some bugs.
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
```
Note: Firebase Message: `@pragma('vm:entry-point')` <br/>
https://github.com/firebase/flutterfire/blob/master/docs/cloud-messaging/receive.md#apple-platforms-and-android

* request permission for post Notification Android 13+
For Android 13 and above, please `requestNotificationPermission` before `showCallkitIncoming`
```dart
await FlutterCallkitIncoming.requestNotificationPermission({
"rationaleMessagePermission": "Notification permission is required, to show notification.",
"postNotificationMessageRequired": "Notification permission is required, Please allow notification permission from setting."
});
```

* Show miss call notification
```dart
this._currentUuid = _uuid.v4();
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
4 changes: 3 additions & 1 deletion android/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#flutter_callkit_incoming
# Issue: https://github.com/hiennguyen92/flutter_callkit_incoming/issues/171
-keep class com.hiennv.flutter_callkit_incoming.** { *; }
-keep class com.hiennv.flutter_callkit_incoming.** { *; }
-keep class com.fasterxml.** { *; }
-keep class org.codehaus.** { *; }
1 change: 1 addition & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<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"/>

<application>

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package com.hiennv.flutter_callkit_incoming

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import androidx.annotation.NonNull
import androidx.annotation.Nullable

import androidx.appcompat.app.AlertDialog
import androidx.core.app.ActivityCompat
import com.hiennv.flutter_callkit_incoming.Utils.Companion.reapCollection

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.*
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import java.lang.ref.WeakReference


/** FlutterCallkitIncomingPlugin */
class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, PluginRegistry.RequestPermissionsResultListener {
companion object {

const val EXTRA_CALLKIT_CALL_DATA = "EXTRA_CALLKIT_CALL_DATA"
Expand Down Expand Up @@ -76,6 +80,7 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
eventHandlers.add(WeakReference(handler))
events.setStreamHandler(handler)
}

}

/// The MethodChannel that will the communication between Flutter and native Android
Expand All @@ -95,10 +100,10 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
callkitNotificationManager?.showIncomingNotification(data.toBundle())
//send BroadcastReceiver
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentIncoming(
requireNotNull(context),
data.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentIncoming(
requireNotNull(context),
data.toBundle()
)
)
}

Expand All @@ -108,30 +113,30 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA

public fun startCall(data: Data) {
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentStart(
requireNotNull(context),
data.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentStart(
requireNotNull(context),
data.toBundle()
)
)
}

public fun endCall(data: Data) {
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
data.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
data.toBundle()
)
)
}

public fun endAllCalls() {
val calls = getDataActiveCalls(context)
calls.forEach {
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
it.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
it.toBundle()
)
)
}
removeAllCalls(context)
Expand All @@ -151,10 +156,10 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
data.from = "notification"
//send BroadcastReceiver
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentIncoming(
requireNotNull(context),
data.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentIncoming(
requireNotNull(context),
data.toBundle()
)
)
result.success("OK")
}
Expand All @@ -167,10 +172,10 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
"startCall" -> {
val data = Data(call.arguments() ?: HashMap())
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentStart(
requireNotNull(context),
data.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentStart(
requireNotNull(context),
data.toBundle()
)
)
result.success("OK")
}
Expand All @@ -194,13 +199,16 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
sendEvent(CallkitConstants.ACTION_CALL_TOGGLE_HOLD, map);
result.success("OK")
}
"isMuted" -> {
result.success(false)
}
"endCall" -> {
val data = Data(call.arguments() ?: HashMap())
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
data.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
data.toBundle()
)
)
result.success("OK")
}
Expand All @@ -212,17 +220,17 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
calls.forEach {
if (it.isAccepted) {
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
it.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentEnded(
requireNotNull(context),
it.toBundle()
)
)
} else {
context?.sendBroadcast(
CallkitIncomingBroadcastReceiver.getIntentDecline(
requireNotNull(context),
it.toBundle()
)
CallkitIncomingBroadcastReceiver.getIntentDecline(
requireNotNull(context),
it.toBundle()
)
)
}
}
Expand All @@ -235,6 +243,15 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
"getDevicePushTokenVoIP" -> {
result.success("")
}
"requestNotificationPermission" -> {
val map = buildMap {
val args = call.arguments
if (args is Map<*, *>) {
putAll(args as Map<String, Any>)
}
}
callkitNotificationManager?.requestNotificationPermission(activity, map)
}
}
} catch (error: Exception) {
result.error("error", error.message, "")
Expand All @@ -247,16 +264,18 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.activity = binding.activity
this.context = binding.activity.applicationContext
instance.context = binding.activity.applicationContext
instance.activity = binding.activity
binding.addRequestPermissionsResultListener(this)
}

override fun onDetachedFromActivityForConfigChanges() {
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
this.activity = binding.activity
this.context = binding.activity.applicationContext
instance.context = binding.activity.applicationContext
instance.activity = binding.activity
binding.addRequestPermissionsResultListener(this)
}

override fun onDetachedFromActivity() {}
Expand All @@ -271,8 +290,8 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA

fun send(event: String, body: Map<String, Any>) {
val data = mapOf(
"event" to event,
"body" to body
"event" to event,
"body" to body
)
Handler(Looper.getMainLooper()).post {
eventSink?.success(data)
Expand All @@ -283,4 +302,12 @@ class FlutterCallkitIncomingPlugin : FlutterPlugin, MethodCallHandler, ActivityA
eventSink = null
}
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray): Boolean {
instance.callkitNotificationManager?.onRequestPermissionsResult(instance.activity, requestCode, grantResults)
return true
}



}
1 change: 1 addition & 0 deletions android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string name="text_decline">Decline</string>
<string name="text_missed_call">Missed call</string>
<string name="text_call_back">Call back</string>
<string name="text_post_notification_message_required">Notification permission is required, Please allow notification permission from setting.</string>
</resources>
5 changes: 5 additions & 0 deletions android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

</style>

<style name="DialogTheme" parent="@style/Theme.AppCompat.Light.Dialog.Alert">

</style>


<style name="TranslucentTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
<item name="android:background">@android:color/transparent</item>
<item name="background">@android:color/transparent</item>
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.hiennv.testing"
minSdkVersion 19
targetSdkVersion 31
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Loading

0 comments on commit deac4f0

Please sign in to comment.