Toxillo
Toxillo

Reputation: 60

Full-Screen Intent not opening on Android 14

I'm building an alarm app for Android and I'm trying to launch a full-screen intent from a notification when the alarm rings while the phone is locked (as the documentation suggests). It works without issues on a Samsung A51 running Android 13 but on my Pixel 8 Pro with Android 14 it doesn't. On Android 14 I get the notification but the screen doesn't wake and there's no full-screen intent. However, when I unlock the phone and lock it again while the notification is still present I get the full-screen intent.

I have a one-activity setup with Jetpack Compose. The BroadcastReceiver simply creates the notification and intent to open the main activity (which would later navigate to the alarm screen) as follows:

val notificationManager = context?.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.createNotificationChannel(mChannel)
val alarmIntent = Intent(context, MainActivity::class.java)
        alarmIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
  val options = ActivityOptions.makeBasic().setPendingIntentCreatorBackgroundActivityStartMode(ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED)
        // Create a pending intent with the above intent
        val fullScreenPendingIntent = PendingIntent.getActivity(
            context, 0, alarmIntent, PendingIntent.FLAG_IMMUTABLE, options.toBundle()
        )

        val builder = NotificationCompat.Builder(context!!, "alarm_channel")
            .setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
            .setContentTitle("My notification")
            .setContentText("Hello World!")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_ALARM)
            .setOngoing(true)
            .setFullScreenIntent(fullScreenPendingIntent, true)
        // Build the notification

        // Show the notification
        with(NotificationManagerCompat.from(context)) {
            notify(Random().nextInt(32), builder.build())
        }

Here's what I tried:

I'm honestly at a loss. I know that they introduced restrictions on full-screen intents with Android 14 but as far as I understood it, I should be fine as long as I have the permission USE_FULL_SCREEN_INTENT. I even upgraded to the Android 15 Beta to see if it's just a bug but it's the same story.

I'm guessing it has something to do with the screen/CPU not activating but I tried everything I could find without success.

Upvotes: 0

Views: 416

Answers (1)

Brown
Brown

Reputation: 21

WakeLock works for me, try using these flags:

PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.ON_AFTER_RELEASE or PowerManager.SCREEN_BRIGHT_WAKE_LOCK

on Android 14 and above, remember to add these permission also:

android.Manifest.permission.TURN_SCREEN_ON

Reference: Doc

Upvotes: 0

Related Questions