Skip to content

Commit

Permalink
1.0.1+7 Fixed issue open app(terminated/background state). Fixed some…
Browse files Browse the repository at this point in the history
… bugs.
  • Loading branch information
hiennguyen92 committed Apr 14, 2022
1 parent 1b4df6b commit c96e47d
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 59 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.1+7

* Fixed issue open app(terminated/background state).
* Fixed some bugs.

## 1.0.1+6

* Add props for text
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca

<br>

iOS: ONLY WORKING ON REAL DEVICE, not on simulator(Callkit framework not working on simulator)
## iOS: ONLY WORKING ON REAL DEVICE, not on simulator(Callkit framework not working on simulator)

<br>

## 🚀&nbsp; Installation

Expand Down Expand Up @@ -242,14 +244,19 @@ 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)
```

<br>

```swift
//OR
let data = flutter_callkit_incoming.Data(id: "44d915e1-5ff4-4bed-bf13-c423048ec97a", nameCaller: "Hien Nguyen", handle: "0123456789", type: 0)
data.nameCaller = "Johnny"
data.extra = ["user": "abc@123", "platform": "ios"]
//... set more data
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(data, fromPushKit: true)
```
<br>

```objc
Expand All @@ -269,7 +276,7 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
<br>

```java
```swift
//send custom event from native
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.sendEventCustom("customEvent", body: ["customKey": "customValue"])

Expand Down Expand Up @@ -348,7 +355,8 @@ A Flutter plugin to show incoming call in your Flutter app(Custom for Android/Ca
<br>

7. Todo
* Add `WakeLock` (background tasks) for Android
*
*

<br>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class CallkitIncomingActivity : Activity() {
private fun onAcceptClick() {
val data = intent.extras?.getBundle(EXTRA_CALLKIT_INCOMING_DATA)
val intent = packageManager.getLaunchIntentForPackage(packageName)?.cloneFilter()
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
if (intent != null) {
val intentTransparent = TransparentActivity.getIntentAccept(this@CallkitIncomingActivity, data)
startActivities(arrayOf(intent, intentTransparent))
Expand All @@ -298,11 +298,11 @@ class CallkitIncomingActivity : Activity() {
val intent =
CallkitIncomingBroadcastReceiver.getIntentDecline(this@CallkitIncomingActivity, data)
sendBroadcast(intent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask()
} else {
finish()
}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// finishAndRemoveTask()
// } else {
// finish()
// }
}

private fun getPicassoInstance(context: Context, headers: HashMap<String, Any?>): Picasso {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ class CallkitNotificationManager(private val context: Context) {
.transform(CircleTransform())
.into(targetLoadAvatarCustomize)
}
if (Build.MANUFACTURER.equals("Xiaomi", ignoreCase = true)) {
//Ignore
} else {
notificationBuilder.setStyle(NotificationCompat.DecoratedCustomViewStyle())
}
notificationBuilder.setStyle(NotificationCompat.DecoratedCustomViewStyle())
notificationBuilder.setCustomContentView(notificationViews)
notificationBuilder.setCustomBigContentView(notificationViews)
notificationBuilder.setCustomHeadsUpContentView(notificationViews)
Expand Down Expand Up @@ -346,7 +342,7 @@ class CallkitNotificationManager(private val context: Context) {

private fun getAcceptPendingIntent(id: Int, data: Bundle): PendingIntent {
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)?.cloneFilter()
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
if (intent != null) {
val intentTransparent = TransparentActivity.getIntentAccept(context, data)
return PendingIntent.getActivities(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "1"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import flutter_callkit_incoming
let nameCaller = handleObj.getDecryptHandle()["nameCaller"] as? String ?? ""
let handle = handleObj.getDecryptHandle()["handle"] as? String ?? ""
let data = flutter_callkit_incoming.Data(id: UUID().uuidString, nameCaller: nameCaller, handle: handle, type: isVideo ? 1 : 0)
//set more data
data.nameCaller = "Johnny"
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.startCall(data, fromPushKit: true)

Expand Down Expand Up @@ -69,6 +70,7 @@ import flutter_callkit_incoming
//set more data
data.extra = ["user": "abc@123", "platform": "ios"]
//data.iconName = ...
//data.....
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(data, fromPushKit: true)
}

Expand Down
6 changes: 4 additions & 2 deletions example/lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class AppRoute {
static Route<Object>? generateRoute(RouteSettings settings) {
switch (settings.name) {
case homePage:
return MaterialPageRoute(builder: (_) => HomePage());
return MaterialPageRoute(
builder: (_) => HomePage(), settings: settings);
case callingPage:
return MaterialPageRoute(builder: (_) => CallingPage());
return MaterialPageRoute(
builder: (_) => CallingPage(), settings: settings);
default:
return null;
}
Expand Down
46 changes: 40 additions & 6 deletions example/lib/calling_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
import 'package:flutter_callkit_incoming_example/navigation_service.dart';

class CallingPage extends StatefulWidget {
@override
Expand All @@ -8,13 +10,45 @@ class CallingPage extends StatefulWidget {
}

class CallingPageState extends State<CallingPage> {
late dynamic calling;

@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
width: double.infinity,
child: Center(
child: Text('Calling...'),
));
calling = ModalRoute.of(context)!.settings.arguments;
print(calling);

return Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
width: double.infinity,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Calling...'),
TextButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () {
FlutterCallkitIncoming.endCall(calling);
calling = null;
NavigationService.instance.goBack();
},
child: Text('End Call'),
)
],
),
)));
}

@override
void dispose() {
super.dispose();
if (calling != null) {
FlutterCallkitIncoming.endCall(calling);
}
}
}
37 changes: 17 additions & 20 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,53 +200,53 @@ class HomePageState extends State<HomePage> {
print(devicePushTokenVoIP);
}


Future<void> listenerEvent(Function? callback) async {
try {
FlutterCallkitIncoming.onEvent.listen((event) {
print(event);
switch (event!.name) {
case CallEvent.ACTION_CALL_INCOMING:
// TODO: received an incoming call
// TODO: received an incoming call
break;
case CallEvent.ACTION_CALL_START:
// TODO: started an outgoing call
// TODO: show screen calling in Flutter
// TODO: started an outgoing call
// TODO: show screen calling in Flutter
break;
case CallEvent.ACTION_CALL_ACCEPT:
// TODO: accepted an incoming call
// TODO: show screen calling in Flutter
NavigationService.instance.pushNamed(AppRoute.callingPage);
// TODO: accepted an incoming call
// TODO: show screen calling in Flutter
NavigationService.instance
.pushNamed(AppRoute.callingPage, args: event.body);
break;
case CallEvent.ACTION_CALL_DECLINE:
// TODO: declined an incoming call
// TODO: declined an incoming call
break;
case CallEvent.ACTION_CALL_ENDED:
// TODO: ended an incoming/outgoing call
// TODO: ended an incoming/outgoing call
break;
case CallEvent.ACTION_CALL_TIMEOUT:
// TODO: missed an incoming call
// TODO: missed an incoming call
break;
case CallEvent.ACTION_CALL_CALLBACK:
// TODO: only Android - click action `Call back` from missed call notification
// TODO: only Android - click action `Call back` from missed call notification
break;
case CallEvent.ACTION_CALL_TOGGLE_HOLD:
// TODO: only iOS
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_MUTE:
// TODO: only iOS
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_DMTF:
// TODO: only iOS
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_GROUP:
// TODO: only iOS
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_AUDIO_SESSION:
// TODO: only iOS
// TODO: only iOS
break;
case CallEvent.ACTION_DID_UPDATE_DEVICE_PUSH_TOKEN_VOIP:
// TODO: only iOS
// TODO: only iOS
break;
}
if (callback != null) {
Expand All @@ -262,7 +262,4 @@ class HomePageState extends State<HomePage> {
textEvents += "${event.toString()}\n";
});
}



}
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class _MyAppState extends State<MyApp> {
WidgetsBinding.instance?.addPostFrameCallback((_) async {
var currentCall = await getCurrentCall();
if (currentCall != null) {
NavigationService.instance.pushNamed(AppRoute.callingPage);
NavigationService.instance
.pushNamed(AppRoute.callingPage, args: currentCall);
}
});
}
Expand Down
18 changes: 8 additions & 10 deletions example/lib/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class NavigationService {
return navigationKey.currentState?.push<T>(route);
}


/// Replace the current route of the navigator by pushing the given route and
/// then disposing the previous route once the new route has finished
/// animating in.
Expand All @@ -55,10 +54,10 @@ class NavigationService {
/// Push the route with the given name onto the navigator, and then remove all
/// the previous routes until the `predicate` returns true.
Future<T?> pushNamedAndRemoveUntil<T extends Object>(
String routeName, {
Object? args,
bool Function(Route<dynamic>)? predicate,
}) async {
String routeName, {
Object? args,
bool Function(Route<dynamic>)? predicate,
}) async {
return navigationKey.currentState?.pushNamedAndRemoveUntil<T>(
routeName,
predicate ?? (_) => false,
Expand All @@ -69,9 +68,9 @@ class NavigationService {
/// Push the given route onto the navigator, and then remove all the previous
/// routes until the `predicate` returns true.
Future<T?> pushAndRemoveUntil<T extends Object>(
Route<T> route, {
bool Function(Route<dynamic>)? predicate,
}) async {
Route<T> route, {
bool Function(Route<dynamic>)? predicate,
}) async {
return navigationKey.currentState?.pushAndRemoveUntil<T>(
route,
predicate ?? (_) => false,
Expand All @@ -97,5 +96,4 @@ class NavigationService {
void popUntil(String route) {
navigationKey.currentState!.popUntil(ModalRoute.withName(route));
}

}
}
Binary file modified images/Xcode-S2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/Xcode-S3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions ios/Classes/SwiftFlutterCallkitIncomingPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ public class SwiftFlutterCallkitIncomingPlugin: NSObject, FlutterPlugin, CXProvi
}
configurAudioSession()
self.answerCall = call
self.callManager?.addCall(call)
sendEvent(SwiftFlutterCallkitIncomingPlugin.ACTION_CALL_ACCEPT, self.data?.toJSON())
action.fulfill()
}
Expand Down Expand Up @@ -426,7 +425,6 @@ public class SwiftFlutterCallkitIncomingPlugin: NSObject, FlutterPlugin, CXProvi
action.fail()
return
}
//call.isMuted = action.isMuted
self.sendEvent(SwiftFlutterCallkitIncomingPlugin.ACTION_CALL_TOGGLE_GROUP, [ "id": action.callUUID.uuidString, "callUUIDToGroupWith" : action.callUUIDToGroupWith?.uuidString])
action.fulfill()
}
Expand All @@ -436,7 +434,6 @@ public class SwiftFlutterCallkitIncomingPlugin: NSObject, FlutterPlugin, CXProvi
action.fail()
return
}
//call.isMuted = action.isMuted
self.sendEvent(SwiftFlutterCallkitIncomingPlugin.ACTION_CALL_TOGGLE_DMTF, [ "id": action.callUUID.uuidString, "digits": action.digits, "type": action.type ])
action.fulfill()
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_callkit_incoming
description: Flutter Callkit Incoming to show callkit screen in your Flutter app.
version: 1.0.1+6
version: 1.0.1+7
homepage: https://github.com/hiennguyen92/flutter_callkit_incoming
repository: https://github.com/hiennguyen92/flutter_callkit_incoming
issue_tracker: https://github.com/hiennguyen92/flutter_callkit_incoming/issues
Expand Down

0 comments on commit c96e47d

Please sign in to comment.