Flutterurl_launcher未在发布模式下启动url
我不知道出于某种原因url_launcher(https://pub.dev/packages/url_launcher)从 google Playstore 下载应用程序后无法正常工作。在调试模式下,它按应有的方式工作。但是在Playstore上上传应用程序并从那里下载后,url启动器没有启动任何url。这是为什么?
import 'package:url_launcher/url_launcher.dart';
onTap: () {
launchURL("https://www.google.com");
},
..............
launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
pubspec.yaml
url_launcher: ^5.7.6
我也添加了 android.permission.INTERNET
我没有使用最新版本,url_launcher所以可能使用最新版本可以解决问题,但问题是最新版本 url_launcher需要最新版本的颤振。升级flutter版本安全吗?由于我的应用程序已经投入生产,我不能冒险引发更多问题
这就是我尝试升级到 url_launcher: ^5.7.10最新版本并运行flutter pub get 时得到的结果
[xxxxx] flutter pub get
Running "flutter pub get" in xxxxx...
The current Flutter SDK version is 1.22.0-9.0.pre.
Because url_launcher >=5.7.7 <6.0.0-nullsafety depends on url_launcher_platform_interface >=1.0.9 <2.0.0-nullsafety which requires Flutter SDK version >=1.22.0 <2.0.0, url_launcher >=5.7.7 <6.0.0-nullsafety is forbidden.
So, because xxxxx depends on url_launcher ^5.7.10, version solving failed.
pub get failed (1; So, because storeifie depends on url_launcher ^5.7.10, version solving failed.)
exit code 1
回答
我在 Android 11(API 级别 30)上遇到了同样的问题——在软件更新之前(以及在我运行早期版本的测试设备上)一切正常——以下似乎让我走上了正确的轨道
https://developer。 android.com/training/basics/intents/package-visibility#all-apps
我通过在 AndroidManifest.xml 中添加以下内容解决了我的问题(尽管它可能不是必需的。)
<activity android:name="io.flutter.plugins.urllauncher.WebViewActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:exported="false"/>
仅此一项是行不通的,然后我添加到 <manifest ... package="com.example.app" 正下方的行中:
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
- Thanks a lot! Adding permission only worked well, had the same issue with API Level 30.