app/src/main/java/dev/equwal/inkrecents/RecentsTileService.kt (1280 bytes)
1 // SPDX-License-Identifier: GPL-3.0-or-later 2 // Copyright (c) 2026 equwal 3 package dev.equwal.inkrecents 4 5 import android.annotation.SuppressLint 6 import android.app.PendingIntent 7 import android.content.Intent 8 import android.os.Build 9 import android.service.quicksettings.TileService 10 11 /** 12 * A tile in the quick settings panel. It opens the recents screen and closes 13 * the panel. 14 * 15 * From Android 14 a tile must hand the system a PendingIntent. The older call 16 * with a plain Intent throws there. 17 */ 18 class RecentsTileService : TileService() { 19 20 // The SDK check below gives each Android version the call that it supports. 21 @SuppressLint("StartActivityAndCollapseDeprecated") 22 override fun onClick() { 23 super.onClick() 24 val intent = Intent(this, RecentsActivity::class.java) 25 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 26 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { 27 startActivityAndCollapse( 28 PendingIntent.getActivity( 29 this, 0, intent, 30 PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT 31 ) 32 ) 33 } else { 34 @Suppress("DEPRECATION") 35 startActivityAndCollapse(intent) 36 } 37 } 38 }