This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun sendEvent(event: String, body: Map<String, Any>) { | |
eventHandlers.reapCollection().forEach { it.get()?.send(event, body) } | |
if (event == CallkitConstants.ACTION_CALL_DECLINE) { | |
for ((name, channel) in methodChannels) { | |
try { | |
channel.invokeMethod("CALL_DECLINED_CUSTOM", "") | |
} catch (e: Exception) { | |
Log.d(EXTRA_CALLKIT_CALL_DATA, e.toString()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CallingKitService { | |
static final CallingKitService _instance = CallingKitService._internal(); | |
factory CallingKitService() { | |
return _instance; | |
} | |
CallingKitService._internal() { | |
MethodChannel('YOUR_CHANNEL_NAME').setMethodCallHandler( | |
(call) async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CallingKitService { | |
static final CallingKitService _instance = CallingKitService._internal(); | |
factory CallingKitService() { | |
return _instance; | |
} | |
CallingKitService._internal() { | |
MethodChannel('YOUR_CHANNEL_NAME').setMethodCallHandler( | |
(call) async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
channel = MethodChannel(flutterEngine?.dartExecutor?.binaryMessenger!!, "YOUR_CHANNEL_NAME") | |
val appOpenedIntent = intent | |
if ( | |
appOpenedIntent != null && | |
appOpenedIntent.action == "com.hiennv.flutter_callkit_incoming.ACTION_CALL_ACCEPT" | |
) { | |
val extras = appOpenedIntent.extras | |
if (extras != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void showCallNotification(Map payload) { | |
var params = CallKitParams( | |
id: Uuid().v1(), | |
nameCaller: payload['name'], | |
appName: 'App Name', | |
avatar: payload['imageUrl'], | |
handle: '0123456789', | |
appLogo: 'assets/images/app_logo.png', | |
duration: 45000, | |
// This is the data that you will be extracting once app is opened |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List < OneTimeWorkRequest > notificationScheduleList = new ArrayList(); | |
// create list of OneTimeRequests for re triggering notifications every 5 minutes after | |
// a new notification is received | |
for (int i = 1; i < 3; i++) { | |
notificationScheduleList.add( | |
new OneTimeWorkRequest.Builder(PushNotificationSchedulerWork.class) // Specify the worker | |
.setInitialDelay(30 * i, TimeUnit.MINUTES) // First one at 30th minute, Next at 60th minute | |
.addTag("PushNotificationSchedulerWork") // Specify a work tag | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PushNotificationSchedulerWork(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { | |
val tag = "PushNotificationSchedulerWork" | |
@RequiresApi(Build.VERSION_CODES.O) | |
override fun doWork(): Result { | |
try { | |
val context = applicationContext | |
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
val activeNotifications = notificationManager.activeNotifications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressLint("NotificationTrampoline") | |
void reTriggerNotification(Context context, Bundle extras, StatusBarNotification notification, String channelId, NotificationManager nm) { | |
NotificationCompat.Builder nb = new NotificationCompat.Builder(context, channelId); | |
Notification n = notification.getNotification(); | |
// ... | |
// Set all attributes you want on your notification. | |
// Set unique group IDs if you're disabling Notification bundling | |
// Set custom layouts, stale notification etc | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// METHOD TO SORT | |
sort() { | |
activeNotifications = notificationManager.getActiveNotifications(); | |
Arrays.sort(activeNotifications, PushNotificationUtil.postTimeComparator); | |
while (activeNotifications.size() > 6) { // You can change this to any number. This defines the limit on notifications | |
StatusBarNotification notification = activeNotifications.remove(0); | |
notificationManager.cancel(notification.getId()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createNotification() { | |
... | |
notificationBuilder.setGroup(getUniqueGroupKey(10)) | |
... | |
} | |
fun getUniqueGroupKey(sizeOfRandomString: Int): String { | |
val random = Random() | |
val sb = StringBuilder(sizeOfRandomString) | |
for (i in 0 until sizeOfRandomString) |
NewerOlder