Skip to content

Commit dd1c872

Browse files
authored
[FIX] Duplicated call onAnswer. New open method. (#111)
* feature: open method openPhoneAccounts * feature: fixed duplicated call onAnswer on VoiceConnection * feature: added support for drawables in notification icon in foreground service
1 parent 5bb6385 commit dd1c872

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final callSetup = <String, dynamic>{
3535
'channelId': 'com.company.my',
3636
'channelName': 'Foreground service for my app',
3737
'notificationTitle': 'My app is running on background',
38-
'notificationIcon': 'Path to the resource icon of the notification',
38+
'notificationIcon': 'mipmap/ic_notification_launcher',
3939
},
4040
},
4141
};

android/src/main/java/com/github/cloudwebrtc/flutter_callkeep/FlutterCallkeepPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
6666

6767
@Override
6868
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
69-
if (!callKeep.HandleMethodCall(call, result)) {
69+
if (!callKeep.handleMethodCall(call, result)) {
7070
result.notImplemented();
7171
}
7272
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ public void setActivity(Activity activity) {
9797
}
9898

9999
public void dispose(){
100+
if (voiceBroadcastReceiver == null || this._context == null) return;
100101
LocalBroadcastManager.getInstance(this._context).unregisterReceiver(voiceBroadcastReceiver);
101102
VoiceConnectionService.setPhoneAccountHandle(null);
103+
isReceiverRegistered = false;
102104
}
103105

104-
public boolean HandleMethodCall(@NonNull MethodCall call, @NonNull Result result) {
106+
public boolean handleMethodCall(@NonNull MethodCall call, @NonNull Result result) {
105107
switch(call.method) {
106108
case "setup": {
107109
setup(new ConstraintsMap((Map<String, Object>)call.argument("options")));
@@ -219,6 +221,9 @@ public boolean HandleMethodCall(@NonNull MethodCall call, @NonNull Result result
219221
}
220222

221223
public void setup(ConstraintsMap options) {
224+
if (isReceiverRegistered) {
225+
return;
226+
}
222227
VoiceConnectionService.setAvailable(false);
223228
this._settings = options;
224229
if (isConnectionServiceAvailable()) {
@@ -243,7 +248,6 @@ public void registerEvents() {
243248
if (!isConnectionServiceAvailable()) {
244249
return;
245250
}
246-
247251
voiceBroadcastReceiver = new VoiceBroadcastReceiver();
248252
registerReceiver();
249253
VoiceConnectionService.setPhoneAccountHandle(handle);

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,20 @@ public void onCallAudioStateChanged(CallAudioState state) {
8383
public void onAnswer() {
8484
super.onAnswer();
8585
Log.d(TAG, "onAnswer called");
86-
87-
setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD);
88-
setAudioModeIsVoip(true);
89-
90-
sendCallRequestToActivity(ACTION_ANSWER_CALL, handle);
91-
sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle);
92-
Log.d(TAG, "onAnswer executed");
86+
Log.d(TAG, "onAnswer ignored");
9387
}
9488

95-
9689
@Override
9790
public void onAnswer(int videoState) {
9891
super.onAnswer(videoState);
99-
Log.d(TAG, "onAnswer called");
92+
Log.d(TAG, "onAnswer videoState called: " + videoState);
10093

10194
setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD);
10295
setAudioModeIsVoip(true);
10396

10497
sendCallRequestToActivity(ACTION_ANSWER_CALL, handle);
10598
sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle);
106-
Log.d(TAG, "onAnswer executed");
99+
Log.d(TAG, "onAnswer videoState executed");
107100
}
108101

109102
@Override

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,17 @@ private void startForegroundService() {
229229
Context context = this.getApplicationContext();
230230
Resources res = context.getResources();
231231
String smallIcon = foregroundSettings.getString("notificationIcon");
232-
notificationBuilder.setSmallIcon(res.getIdentifier(smallIcon, "mipmap", context.getPackageName()));
232+
String mipmap = "mipmap/";
233+
String drawable = "drawable/";
234+
if (smallIcon.contains(mipmap)) {
235+
notificationBuilder.setSmallIcon(
236+
res.getIdentifier(smallIcon.replace(mipmap, ""),
237+
"mipmap", context.getPackageName()));
238+
} else if (smallIcon.contains(drawable)) {
239+
notificationBuilder.setSmallIcon(
240+
res.getIdentifier(smallIcon.replace(drawable, ""),
241+
"drawable", context.getPackageName()));
242+
}
233243
}
234244

235245
Log.d(TAG, "[VoiceConnectionService] Starting foreground service");

lib/src/api.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ class FlutterCallkeep extends EventManager {
310310
return false;
311311
}
312312

313+
Future<void> openPhoneAccounts() async {
314+
_openPhoneAccounts();
315+
}
316+
313317
Future<void> _openPhoneAccounts() async {
314318
if (!Platform.isAndroid) {
315319
return;

0 commit comments

Comments
 (0)