【发布时间】: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