如何在 Android Oreo 中删除固定的快捷方式徽章?

问题描述 投票:0回答:1

如何在 Android Oreo 中添加屏幕快捷方式,我尝试了动态、静态和固定快捷方式方法,但在安装应用程序时主屏幕中只有固定快捷方式以及徽章图标,问题是我无法删除或隐藏应用程序快捷方式的徽章,我需要创建一个简单整洁的应用程序快捷方式,如“清理大师快捷方式”

android android-manifest android-8.0-oreo android-shortcut pinned-shortcut
1个回答
0
投票

有两种技术可以通过编程方式创建任何没有徽章的应用程序的快捷方式

  1. 通过使用小部件

  2. 创建一个带有透明启动器图标的 Activity [1]:https://i.stack.imgur.com/EZVAX.png

    使用此功能将此活动设置为快捷方式

shortcutInfo.setActivity(ComponentName(mActivity!!, OpenAppActivity::class.java))

第二个选项的完整方法

fun addShortcut(bitmap: Bitmap) {
    val launchIntent =
        mActivity!!.packageManager.getLaunchIntentForPackage(MApplication.packageNameApp.takeIf { it.isNotEmpty() }
            ?: mActivity!!.packageName)
    val shortcutInfo = ShortcutInfoCompat.Builder(
        mActivity!!.applicationContext,
        mainViewModel.selectedApp!!.appName
    )
        .setIntent(launchIntent!!)
        .setShortLabel("test")
        .setAlwaysBadged()
        .setActivity(ComponentName(mActivity!!, OpenAppActivity::class.java))
        .setIcon(IconCompat.createWithBitmap(bitmap!!)).build()
    val broadcastIntent = Intent(Intent.ACTION_CREATE_SHORTCUT)
    mActivity?.registerReceiver(
        object : BroadcastReceiver() {
            override fun onReceive(
                c: Context?, intent: Intent
            ) {
                Toast.makeText(
                    mActivity!!.applicationContext,
                    "Icon Created",
                    Toast.LENGTH_SHORT
                ).show()
                mActivity!!.unregisterReceiver(this)
            }
        }, IntentFilter(
            Intent.ACTION_CREATE_SHORTCUT
        ), Context.RECEIVER_NOT_EXPORTED
    )
    val successCallback = PendingIntent.getBroadcast(
        mActivity!!,
        99,
        broadcastIntent,
        PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
    )
    ShortcutManagerCompat.requestPinShortcut(
        requireContext(),
        shortcutInfo,
        successCallback.intentSender
    )
}
© www.soinside.com 2019 - 2024. All rights reserved.