Skip to content

Commit 740023e

Browse files
authored
Fix background call (#25)
* fix background call. * Fix iOS, close #23. * Fix typo. * More changes. * Remove EventChannel. * Change FlutterCallKeep as a singleton. * Add CallKeepPushKitToken event. * Add firebase_messaging to example. * update.
1 parent 9c065ca commit 740023e

File tree

17 files changed

+287
-92
lines changed

17 files changed

+287
-92
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# callkeep
2-
iOS CallKit and Android ConnectionService for Flutter
2+
* iOS CallKit and Android ConnectionService for Flutter
3+
* Support FCM and PushKit

android/src/main/java/io/wazo/callkeep/CallKeepModule.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ public boolean HandleMethodCall(@NonNull MethodCall call, @NonNull Result result
217217
public void setup(ConstraintsMap options) {
218218
VoiceConnectionService.setAvailable(false);
219219
this._settings = options;
220-
221220
if (isConnectionServiceAvailable()) {
222221
this.registerPhoneAccount();
223222
this.registerEvents();
@@ -598,7 +597,7 @@ private void registerPhoneAccount(Context appContext) {
598597
}
599598

600599
private void sendEventToFlutter(String eventName, @Nullable ConstraintsMap params) {
601-
_eventChannel.invokeMethod(eventName, params != null? params.toMap() : null);
600+
_eventChannel.invokeMethod(eventName, params.toMap());
602601
}
603602

604603
private String getApplicationName(Context appContext) {
@@ -735,10 +734,10 @@ public void onReceive(Context context, Intent intent) {
735734
sendEventToFlutter("CallKeepDidReceiveStartCallAction", args);
736735
break;
737736
case ACTION_AUDIO_SESSION:
738-
sendEventToFlutter("CallKeepDidActivateAudioSession", null);
737+
sendEventToFlutter("CallKeepDidActivateAudioSession", args);
739738
break;
740739
case ACTION_CHECK_REACHABILITY:
741-
sendEventToFlutter("CallKeepCheckReachability", null);
740+
sendEventToFlutter("CallKeepCheckReachability", args);
742741
break;
743742
case ACTION_WAKE_APP:
744743
Intent headlessIntent = new Intent(_context, CallKeepBackgroundMessagingService.class);

android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class VoiceConnectionService extends ConnectionService {
5656
private static Boolean isReachable;
5757
private static String notReachableCallUuid;
5858
private static ConnectionRequest currentConnectionRequest;
59-
private static PhoneAccountHandle phoneAccountHandle;
59+
private static PhoneAccountHandle phoneAccountHandle = null;
6060
private static String TAG = "RNCK:VoiceConnectionService";
6161
public static Map<String, VoiceConnection> currentConnections = new HashMap<>();
6262
public static Boolean hasOutgoingCall = false;

example/.metadata

Lines changed: 0 additions & 10 deletions
This file was deleted.

example/android/app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ if (flutterVersionName == null) {
2222
}
2323

2424
apply plugin: 'com.android.application'
25+
apply plugin: 'com.google.gms.google-services'
2526
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2627

28+
dependencies {
29+
// Add the dependencies for any other desired Firebase products
30+
// https://firebase.google.com/docs/android/setup#available-libraries
31+
implementation 'com.google.firebase:firebase-messaging:20.3.0'
32+
}
33+
2734
android {
2835
compileSdkVersion 28
2936

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
2828
<!-- END OPTIONAL PERMISSIONS -->
2929
<application
30-
android:name="io.flutter.app.FlutterApplication"
30+
android:name=".Application"
3131
android:label="flutter_callkeep_example"
3232
android:icon="@mipmap/ic_launcher">
3333
<activity
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.cloudwebrtc.flutter_callkeep_example;
2+
3+
import android.os.Bundle;
4+
5+
import androidx.annotation.CallSuper;
6+
7+
import io.flutter.app.FlutterApplication;
8+
import io.flutter.app.FlutterActivity;
9+
import io.flutter.plugin.common.PluginRegistry;
10+
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
11+
import io.flutter.plugins.GeneratedPluginRegistrant;
12+
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
13+
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
14+
import com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin;
15+
16+
public class Application extends FlutterApplication implements PluginRegistrantCallback {
17+
@Override
18+
public void onCreate() {
19+
super.onCreate();
20+
FlutterFirebaseMessagingService.setPluginRegistrant(this);
21+
}
22+
23+
@Override
24+
public void registerWith(PluginRegistry pluginRegistry) {
25+
FirebaseMessagingPlugin.registerWith(pluginRegistry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
26+
FlutterCallkeepPlugin.registerWith(pluginRegistry.registrarFor("com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin"));
27+
}
28+
}

example/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ buildscript {
66

77
dependencies {
88
classpath 'com.android.tools.build:gradle:3.5.0'
9+
classpath 'com.google.gms:google-services:4.3.4'
910
}
1011
}
1112

example/ios/Runner/AppDelegate.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ @implementation AppDelegate
66

77
- (BOOL)application:(UIApplication *)application
88
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
9-
[GeneratedPluginRegistrant registerWithRegistry:self];
10-
// Override point for customization after application launch.
11-
return [super application:application didFinishLaunchingWithOptions:launchOptions];
9+
[GeneratedPluginRegistrant registerWithRegistry:self];
10+
// Override point for customization after application launch.
11+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
1212
}
1313

14-
- (BOOL)application:(UIApplication *)application
15-
continueUserActivity:(NSUserActivity *)userActivity
16-
restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler {
14+
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler {
1715
return [CallKeep application:application
1816
continueUserActivity:userActivity
1917
restorationHandler:restorationHandler];
20-
2118
}
19+
2220
@end

example/ios/Runner/Info.plist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<true/>
2525
<key>UIBackgroundModes</key>
2626
<array>
27-
<string>fetch</string>
2827
<string>remote-notification</string>
2928
<string>voip</string>
3029
</array>

0 commit comments

Comments
 (0)