Полное уведомлениеAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Полное уведомление

Сообщение Anonymous »

Я пытаюсь создать полноэкранное уведомление о намерениях, но я застрял. Например, когда приходит вызов, вызововый пользовательский интерфейс показывает, даже когда вызовое приложение не открыто. Но это только показывает уведомления, но не идет полный экран. < /P>
class MyFirebaseMessagingService : FirebaseMessagingService() {

override fun onNewToken(token: String) {
Log.d("FCM", "New token: $token")
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
Log.d("FCM", "Message received")
navigate()
}

private fun navigate() {
val activityIntent = Intent(this, ReceiveMessage::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}

val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)

val notification = NotificationCompat.Builder(this, getString(R.string.CHANNEL_ID))
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Incoming Call")
.setContentText("Someone is calling you...")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setFullScreenIntent(fullScreenPendingIntent, true)
.setAutoCancel(false)
.setOngoing(true)
.build()

// Start a foreground service to show notification with full screen intent
val serviceIntent = Intent(this, CallForegroundService::class.java).apply {
putExtra("notification", notification)
}
ContextCompat.startForegroundService(this, serviceIntent)
}
}

< /code>

class MyApplication: Application() {
override fun onCreate() {
super.onCreate()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create the NotificationChannel.
val name = getString(R.string.channel_name)
val descriptionText = getString(R.string.channel_description)
val channelId = getString(R.string.CHANNEL_ID)
val importance = NotificationManager.IMPORTANCE_HIGH
val mChannel = NotificationChannel(channelId, name, importance)
mChannel.description = descriptionText
mChannel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
// Register the channel with the system. You can't change the importance
// or other notification behaviors after this.
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
}
}
}
< /code>
class CallForegroundService : Service() {

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = intent?.getParcelableExtra("notification")
if (notification != null) {
Log.d(TAG, "Starting foreground with notification")
startForeground(1, notification)
} else {
Log.e(TAG, "Notification is null")
}
// Stop service after 30 seconds if not answered
Handler(Looper.getMainLooper()).postDelayed({ stopSelf() }, 30000)
return START_NOT_STICKY
}

override fun onBind(intent: Intent?): IBinder? = null
}


Подробнее здесь: https://stackoverflow.com/questions/796 ... -messaging
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»