Samsung A10 android 11 updated, Galaxy S9 and Galaxy S10 tested on these devices but its not working
This code is only for android Oreo and above
Here is the code which I used for creating the shortcut in android programmatically. In all other devices its work perfectly but on this specific device it create the short but generate my own app shortcut not for desired.
val shortcutIntent = finalPackageName?.let {
context?.packageManager!!.getLaunchIntentForPackage(
it
)
}
val shortcutManager: ShortcutManager? = context?.getSystemService(ShortcutManager::class.java)
if (shortcutManager != null) {
if (shortcutManager.isRequestPinShortcutSupported) {
val shortcut = ShortcutInfo.Builder(context, "unique_id")
.setShortLabel(finalAppName)
.setLongLabel("Open the Android Docu")
.setIcon(Icon.createWithBitmap(finalBitmap))
.setIntent(shortcutIntent!!)
.build()
((activity) as MainActivity).registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
findNavController().navigate(R.id.resultFragment)
context.unregisterReceiver(this)
}
}, IntentFilter("test_action"))
val intent = Intent("test_action")
val pendingIntent = PendingIntent.getBroadcast(context, 123, intent, 0)
shortcutManager.requestPinShortcut(shortcut, pendingIntent.intentSender)
} else
Toast.makeText(
context,
"Pinned shortcuts are not supported!",
Toast.LENGTH_SHORT
).show()
}
I solved it
then go to your main activity and get the intent data