【问题标题】:How to create pinnedshortcuts in flutter如何在颤振中创建固定快捷方式
【发布时间】:2022-10-09 03:25:27
【问题描述】:

我四处寻找,但没有运气。没有可以帮助您创建固定快捷方式的包。快速链接和flutter_shortcuts 没有用。他们都带有糟糕的文档并且没有支持。那里提到的电子邮件也无法访问。

基本上,我正在 Flutter 中编写一个 file_manager 类的应用程序。我想让用户在homescreen 上创建文件夹或文件的快捷方式。我使用 Kotlin 代码实现了这一点。但是当用户点击图标时,它会打开应用程序的mainscreen,在 Kotlin 中是Mainactivity

我在 Kotlin 中看不到其他屏幕。

下面提到的是我的 Kotlin 代码。

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)

        }
    }
}

我实际上不确定单击图标时如何告诉颤振在我的应用程序中打开特定路径。

【问题讨论】:

    标签: flutter kotlin pinned-shortcut


    【解决方案1】:

    是的,我终于找到了解决问题的方法。

    我在颤振中使用了 receive_intent 包来接收意图。

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

    在运行应用程序之前使用 getintialText() 数据在 main.dart 文件中捕获相同的内容。

    此外,当 App 加载到内存中时。来自意图的数据被捕获为流。

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      相关资源
      最近更新 更多