Я пытаюсь создать Heads Up уведомление в родном скрипте углового приложения.Я следовал инструкциям из двух ссылок ниже и копировал логику в собственный скрипт.Он может создавать уведомления правильно, но я не вижу хедз-апов, как это
https://stackoverflow.com/a/50296323. код собственного сценария, как показано ниже:
public postNotification(title: string, msg: string) {
var context = app.android.context;
let channelId = "12345678";
let channel = new android.app.NotificationChannel(channelId, "Channel title", android.app.NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Channel description")
var manager = context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
var builder = new androidx.core.app.NotificationCompat.Builder(context, channelId);
builder.setSmallIcon(android.R.drawable.btn_star_big_on)
.setContentTitle(title)
.setContentText(msg)
.setDefaults(android.app.Notification.DEFAULT_ALL)
.setPriority(androidx.core.app.NotificationCompat.PRIORITY_HIGH)
let notificationManagerCompat = (<any>androidx.core.app.NotificationManagerCompat).from(context);
notificationManagerCompat.notify(0, builder.build());
}
https://v4all123.blogspot.com/2018/11/simple-example-of-heads-up-notification.html собственный код:
public sendNotification(title: string, msg: string) {
var activity = app.android.foregroundActivity || app.android.startActivity;
var notifyManager = null
var NOTIFY_ID = 1002
var name = "KotlinApplication"
var id = "kotlin_app"
var description = "kotlin_app_first_channel"
var intent
var pendingIntent
var builder
if (notifyManager == null) {
notifyManager = activity!!.getSystemService(android.content.Context.NOTIFICATION_SERVICE)
}
var importance = android.app.NotificationManager.IMPORTANCE_HIGH
var mChannel = notifyManager.getNotificationChannel(id)
if (mChannel == null) {
mChannel = new android.app.NotificationChannel(id, name, importance)
mChannel.description = description
mChannel.enableVibration(true)
mChannel.lightColor = "GREEN"
mChannel.vibrationPattern = [100, 200, 300, 400, 500, 400, 300, 200, 400]
notifyManager.createNotificationChannel(mChannel)
}
builder = new androidx.core.app.NotificationCompat.Builder(activity!!, id)
intent = new android.content.Intent(activity, (<any>com).tns.NativeScriptActivity.class)
intent.flags = android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP || android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP
pendingIntent = android.app.PendingIntent.getActivity(activity, 0, intent, 0)
builder.setContentTitle("Heads Up Notification") // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(msg) // required
.setDefaults(android.app.Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker("Notification")
.setVibrate([100, 200, 300, 400, 500, 400, 300, 200, 400])
var dismissIntent = new android.content.Intent(activity, (<any>com).tns.NativeScriptActivity.class)
dismissIntent.action = "DISMISS"
dismissIntent.flags = android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP || android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP
var pendingDismissIntent = android.app.PendingIntent.getActivity(activity, 0, dismissIntent,
android.app.PendingIntent.FLAG_UPDATE_CURRENT)
var dismissAction = new androidx.core.app.NotificationCompat.Action(android.R.drawable.ic_baseline_notification_important_24px,
"DISMISS", pendingDismissIntent)
builder.addAction(dismissAction)
var notification = builder.build()
notifyManager.notify(NOTIFY_ID, notification)
}