How to create pinnedshortcuts in flutter

281 Views Asked by At

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.

1

There are 1 best solutions below

0
On

Yes, I finally found a solution to my problem.

I used receive_intent package in flutter to receive intent.

.setIntent(Intent(Intent.ACTION_VIEW, <usedFolderPath>, context, MainActivity::class.java)).putExtra("FolderName",<folderName>

Same was capture in flutter in main.dart file using getintialText() data in before run app.

Also, when App is loaded in memory. The data from intent is captured as stream.