Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize heads-up notification #5

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions android/src/main/kotlin/co/doneservices/callkeep/CallKeep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class CallKeep(private val channel: MethodChannel, private var applicationContex
backToForeground(result)
}
"displayCustomIncomingCall" -> {
displayCustomIncomingCall(call.argument("packageName")!!, call.argument("className")!!, call.argument("icon")!!, call.argument("extra")!!)
displayCustomIncomingCall(call.argument("packageName")!!, call.argument("className")!!, call.argument("icon")!!, call.argument("extra")!!, call.argument("contentTitle")!!, call.argument("answerText")!!, call.argument("declineText")!!)
result.success(null)
}
"dismissCustomIncomingCall" -> {
Expand Down Expand Up @@ -397,7 +397,7 @@ class CallKeep(private val channel: MethodChannel, private var applicationContex
result.success(null)
}

private fun displayCustomIncomingCall(packageName: String, className: String, icon: String, extra: HashMap<String, String>) {
private fun displayCustomIncomingCall(packageName: String, className: String, icon: String, extra: HashMap<String, String>, contentTitle: String, answerText: String, declineText: String) {
val notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

var launchIntent = Intent()
Expand Down Expand Up @@ -431,9 +431,9 @@ class CallKeep(private val channel: MethodChannel, private var applicationContex
builder.setPriority(NotificationCompat.PRIORITY_MAX)
builder.setAutoCancel(true)

builder.setContentTitle("Incoming call")
builder.addAction(0, "Decline", PendingIntent.getActivity(applicationContext, 1, declineIntent, PendingIntent.FLAG_CANCEL_CURRENT))
builder.addAction(0, "Answer", PendingIntent.getActivity(applicationContext, 2, answerIntent, PendingIntent.FLAG_CANCEL_CURRENT))
builder.setContentTitle(contentTitle)
builder.addAction(0, declineText, PendingIntent.getActivity(applicationContext, 1, declineIntent, PendingIntent.FLAG_CANCEL_CURRENT))
builder.addAction(0, answerText, PendingIntent.getActivity(applicationContext, 2, answerIntent, PendingIntent.FLAG_CANCEL_CURRENT))

notificationManager.notify(NOTIFICATION_ID, builder.build())
}
Expand Down
20 changes: 18 additions & 2 deletions lib/flutter_callkeep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,27 @@ class CallKeep {
await _channel.invokeMethod('backToForeground');
}

static Future<void> displayCustomIncomingCall(String packageName, String className, {@required String icon, Map<String, dynamic> extra}) async {
static Future<void> displayCustomIncomingCall(
String packageName,
String className, {
@required String icon,
Map<String, dynamic> extra,
String contentTitle,
String answerText,
String declineText,
}) async {
assert(packageName != null);
assert(className != null);
assert(icon != null);
await _channel.invokeMethod('displayCustomIncomingCall', {'packageName': packageName, 'className': className, 'icon': icon, 'extra': extra ?? Map()});
await _channel.invokeMethod('displayCustomIncomingCall', {
'packageName': packageName,
'className': className,
'icon': icon,
'extra': extra ?? Map(),
'contentTitle': contentTitle ?? 'Incoming call',
'answerText': answerText ?? 'Answer',
'declineText': declineText ?? 'Decline',
});
}

static Future<void> dismissCustomIncomingCall() async {
Expand Down