How to remove pinned short cut badge in Android Oreo?

671 views Asked by At

How to add screen shortcut in Android Oreo, I tried dynamic, static and pinned shortcut methods, but only pinned shortcut is comes in the home screen while installing the application along with the badge icon, The problem is I can’t remove or hide the badge of the App shortcut, I need to create a plain and neat App short cut like “Clean master shortcut“

1

There are 1 answers

0
XaMi On

There are two techniques through this you can create a shortcut programmatically of any app without badge

  1. By using Widget

  2. Create an Activity with transparent launcher icon [1]: https://i.stack.imgur.com/EZVAX.png

    use this for set this activity to shortcut

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

Complete method of 2nd option

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
    )
}