osrl
osrl

Reputation: 7848

Why doesn't full Screen Intent doesn't display on lock screen

I know this question is asked many times. I've already tried every answer but I couldn't find what's wrong with my code.

I'm trying to show a notification when I receive an incoming call. I start a foreground service when a push notification is received to listen incoming calls. After a while, the actual incoming call is received and I display a notification using the code below. The problem is, this notification should be displayed as a full screen activity when the phone is locked. Instead, it only vibrates. When I unlock the screen, I can see the normal notification on the notification tray. If the phone is unlocked, I can also see the heads up notification.

fun createIncomingCallChannel(
        context: Context,
        notificationManager: NotificationManagerCompat
    ) {
        // Create incoming calls notification channel
        val id = INCOMING_CALL_ID
        val name = context.getString(R.string.notification_channel_incoming_call_name)
        val description = context.getString(R.string.notification_channel_incoming_call_name)
        val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
        channel.description = description
        channel.enableVibration(true)
        channel.enableLights(true)
        channel.setShowBadge(true)
        notificationManager.createNotificationChannel(channel)
    }

fun createIncomingCallNotification(
        context: Context,
        notificationsManager: NotificationsManager
    ): Notification {
        val incomingCallNotificationIntent = Intent(context, CallActivity::class.java)
        incomingCallNotificationIntent.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_FROM_BACKGROUND
        )
        val pendingIntent = PendingIntent.getActivity(
            context,
            0,
            incomingCallNotificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
        )
        val displayName: String = "Foo"
        val address: String = "Bar"
        val info: String = "Incoming Call"

        val notificationLayoutHeadsUp = RemoteViews(
            context.packageName,
            R.layout.call_incoming_notification_heads_up
        )
        notificationLayoutHeadsUp.setTextViewText(R.id.caller, displayName)
        notificationLayoutHeadsUp.setTextViewText(R.id.sip_uri, address)
        notificationLayoutHeadsUp.setTextViewText(R.id.incoming_call_info, info)

        val builder = NotificationCompat.Builder(
            context,
            INCOMING_CALL_ID
        )
            .setStyle(NotificationCompat.DecoratedCustomViewStyle())
            .addPerson(Person.Builder()
                .setName(displayName)
                .setKey(displayName)
                .build())
            .setSmallIcon(R.drawable.ic_stat_onesignal_default)
            .setContentTitle(displayName)
            .setContentText(context.getString(R.string.incoming_call_notification_title))
            .setCategory(NotificationCompat.CATEGORY_CALL)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(false)
            .setShowWhen(true)
            .setOngoing(true)
            .setFullScreenIntent(pendingIntent, true)
            .addAction(notificationsManager.getCallDeclineAction(notifiable))
            .addAction(notificationsManager.getCallAnswerAction(notifiable))
            .setCustomHeadsUpContentView(notificationLayoutHeadsUp)
            .setContentIntent(pendingIntent)

        return builder.build()
    }

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
...
<activity android:name=".ui.CallActivity"
            android:configChanges="orientation|screenSize|layoutDirection"
            android:theme="@style/Base.Theme.WhatsGo"
            android:launchMode="singleTask"
            android:turnScreenOn="true"
            android:showWhenLocked="true" />

onCreate of CallActivity:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
    setShowWhenLocked(true)
    setTurnScreenOn(true)

    val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
    keyguardManager.requestDismissKeyguard(this, null)
}
super.onCreate(savedInstanceState)

Upvotes: 0

Views: 708

Answers (1)

osrl
osrl

Reputation: 7848

I've found out that somewhere in my code (getCallAnswerAction exactly) while creating a pending intent, I unintentionally called context.startActivity. (happened while copy pasteing) This somehow caused the full screen intent not to start.

Upvotes: 0

Related Questions