赞
踩
一、APP 实现被打开
创建URL scheme
修改/app/src/mian/AndroidManifest.xml配置
配置
scheme="xxxxxx"
android:host="xxxxxx"
android:pathPrefix="/xxxxxx"
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.BROWSABLE" />
- <data android:scheme="demoScheme" android:host="host" android:pathPrefix="/path/subpath" />
- </intent-filter>
重新编译APP;
注册完成,APP已经可以被第三方调用了;
二、打开第三方APP
安装插件:url_launcher: ^5.7.10
- launchURL() async {
- const url = 'demoScheme://host/path/subpath';
- if (await canLaunch(url)) {
- // 判断当前手机是否安装某app. 能否正常跳转
- await launch(url);
- } else {
- // 无安装APP
- }
- }
三、接收跳转参数:
- String _initialLink;
- Uri _initialUri;
-
- @override
- void initState() {
- super.initState();
- initPlatformStateForStringUniLinks();
- }
-
- /// 接收跳转数据
- initPlatformStateForStringUniLinks() async {
- getLinksStream().listen((String link) {
- print('got link: $link');
- }, onError: (err) {
- print('got err: $err');
- });
-
- _initialLink = null;
- _initialUri = null;
- try {
- _initialLink = await getInitialLink();
-
- print('initial link: $_initialLink');
- if (_initialLink != null) {
- _initialUri = Uri.parse(_initialLink);
- }
- } on PlatformException {
- _initialLink = null;
- _initialUri = null;
- print('Failed to get initial link.');
- } on FormatException {
- _initialLink = null;
- _initialUri = null;
- print('Failed to parse the initial link as Uri.');
- }
-
- if (!mounted) return;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。