Flutter:将快捷方式添加到启动器菜单和主屏幕 [英] Flutter: Add shortcuts to launcher menu and home screen

查看:300
本文介绍了Flutter:将快捷方式添加到启动器菜单和主屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用相似的标题检查了这个问题:如何可以在启动器主屏幕上放置应用程序图标吗?

I checked this question with similar title: How can I place app icon on launcher home screen?

但是在这个问题中,提问者想在安装过程中自动添加应用程序快捷方式,这不是我的问题.我正在尝试使用Flutter构建基本的Web浏览器.我想在主屏幕以及启动器菜单(列出所有已安装的应用程序)中添加网站快捷方式.有什么办法可以做到吗?

But in this question questioner wants to add app shortcut automatically during installation, which is not my problem. I am trying to build a basic web browser using flutter. I want to add website shortcuts in home screen and also in launcher menu (where all installed apps are listed). Is there any way I can do that?

推荐答案

您可以使用动态链接( https://pub.dev/packages/firebase_dynamic_links ).

You can use Dynamic Linking (https://pub.dev/packages/firebase_dynamic_links).

这样,您可以使用生成的链接来获取参数,例如要打开的URL,全屏显示,新标签页或窗口显示等. 发送电子邮件的方式与"mailto:asd@asd.com"相同.您可以将动态链接设置为"yourappname/openUrl = http://google.com".然后,在Flutter应用程序中,您将检测到与您的应用程序ID相匹配的动态链接,并且将能够获取参数并根据该参数执行操作.

This way, you can use a generated link to get parameters like what URL to open, if its fullscreen, if it's a new tab or window, and so on. It works the same way as 'mailto:asd@asd.com' to send emails. You can set your dynamic links as 'yourappname/openUrl=http://google.com'. Then, in your Flutter app, you will detect that dynamic linking that matches with your app id, and you will be able to get the parameters and take actions according to that.

看看此Firebase动态链接库的下一个示例:

Take a look at the next example of this Firebase Dynamic Links library:

final ShortDynamicLink shortenedLink = await DynamicLinkParameters.shortenUrl(
  Uri.parse('https://example.page.link/?link=https://example.com/&apn=com.example.android&ibn=com.example.ios'),
  DynamicLinkParametersOptions(ShortDynamicLinkPathLength.unguessable),
);

这样,您可以解析多个查询并实现您的目标.

This way, you can parse multiple queries and achieve your goal.

这篇关于Flutter:将快捷方式添加到启动器菜单和主屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆