Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun sendNotificationOptions(title: String?, message: String?, action: String?, packagename: String?, id: Long?) {
- Debug.e("--- title: $title\n--- message: $message\n--- action: $action\n--- packagename: $packagename\n--- id: $id")
- var intent: Intent? = null
- var pendingIntent: PendingIntent? = null
- if (action == "install" || action == "update" || action == "rate") {
- val install_intent = Intent(Intent.ACTION_VIEW, Uri.parse(AndroidUtils.gotoMaketStore(packagename)))
- pendingIntent = PendingIntent.getActivity(applicationContext, 0, install_intent, PendingIntent.FLAG_ONE_SHOT)
- }
- val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
- val channelID = applicationContext.getString(R.string.default_notification_channel_id)
- val builder = NotificationCompat.Builder(applicationContext, channelID)
- val drawable = ContextCompat.getDrawable(applicationContext, R.mipmap.ic_launcher)
- val bitmap = (drawable as BitmapDrawable).bitmap
- val notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- val CHANNEL_NAME = "CHANNEL_NAME"
- val CHANNEL_DESCRIPTION = "CHANNEL_DESCRIPTION"
- val notificationChannel = NotificationChannel (channelID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT)
- notificationChannel.setDescription(CHANNEL_DESCRIPTION)
- notificationChannel.enableVibration(true)
- notificationChannel.enableLights(true)
- notificationChannel.canShowBadge()
- notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC)
- notificationChannel.setLightColor(ContextCompat.getColor(applicationContext, R.color.colorAccent))
- notificationManager.createNotificationChannel(notificationChannel)
- }
- val notification = builder.setContentIntent(pendingIntent)
- .setSmallIcon(R.mipmap.ic_launcher)
- .setLargeIcon(bitmap)
- .setTicker(applicationContext.getString(R.string.app_name))
- .setContentTitle(title)
- .setStyle(NotificationCompat.BigTextStyle().bigText(message))
- .setAutoCancel(false)
- .setSound(defaultSoundUri)
- .setDefaults(Notification.DEFAULT_ALL)
- .setContentText(message).build()
- notification.flags = Notification.FLAG_AUTO_CANCEL
- notificationManager.notify(System.currentTimeMillis().toInt(), notification)
- AndroidDeviceInfo.Vibrate(applicationContext, 1000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement