I searched all around but had no luck. There is no package that can help you create pinned shortcuts. Quicklinks and flutter_shortcuts are of no use. They both come with poor documentation and no support. The email mentioned there not reachable as well.
Basically, I am writing a file_manager kind of app in Flutter. I want to let the user create a shortcut to a folder or file on homescreen
. I achieved this using the Kotlin code. But when the user clicks on the icon it opens the mainscreen
of the app which is Mainactivity
in Kotlin.
I don't see other screen in Kotlin.
Mentioned below is my Kotlin code.
private fun createShortcut(context:Context,folderId:String, folderShortLabel:String, folderLongLabel:String,folderPath:String){
if (VERSION.SDK_INT>=28){
val shortcutManager=context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
if (shortcutManager.isRequestPinShortcutSupported){
val pinShortcutInfo = ShortcutInfo.Builder(context,folderId)
.setShortLabel(folderShortLabel)
.setLongLabel(folderLongLabel)
.setIcon(Icon.createWithResource(context,R.drawable.ic_lock_lock))
.setIntent(Intent(Intent.ACTION_VIEW, null, context, MainActivity::class.java))
.build()
val pinShortcallBackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo)
val successCallBack =PendingIntent.getBroadcast(context,0,pinShortcallBackIntent,0)
shortcutManager.requestPinShortcut(pinShortcutInfo,successCallBack.intentSender)
}
}
}
I am actually not sure how to tell flutter to open a particular path in my app when the icon is clicked.