为什么这个包不能在颤振上工作?



我想使用url_launcher包。这个软件包显然可以在Android 11虚拟设备上运行,但不能在真正的Android 11和Android 12设备上运行。然而,它适用于9和7。

这是我的build.gradle配置

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.gelir_mii"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

这是的代码块

void openWhatsapp() async {
var whatsapp = '+9033823498234';
var whatsappURL = Uri.parse(
'whatsapp://send?phone=$whatsapp&text=Merhaba, danışmanlık hakkında bilgi almak istiyorum.');
if (await canLaunchUrl(whatsappURL)) {
await launchUrl(whatsappURL);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("WhatsApp is not installed on the device"),
),
);
}
}

非常感谢:(

将传递给canLaunchUrl的任何URL方案添加为AndroidManifest.xml中的条目,否则在大多数情况下,从Android 11(API 30(或更高版本开始,它将返回false。必须将元素作为根元素的子元素添加到清单中。

<!-- Provide required visibility configuration for API level 30 and above -->
<queries>
<!-- If your app checks for SMS support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<!-- If your app checks for call support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>

请查看pub配置:https://pub.dev/packages/url_launcher

对于使用您的代码发送whatsapp消息,我希望您可能已经阅读了url_launcher的Readme.md部分,并且已经按照那里的描述配置了url方案。

在自述文件安卓&iOS配置检查,如果您的代码不工作,则检查

var whatsappURL = Uri.parse(
'whatsapp://send?phone=$whatsapp&text=Merhaba, danışmanlık hakkında bilgi almak istiyorum.');

因此,请检查您的$whatsapp号码的格式是否为911234567890,如果您的电话号码确实包含任何特殊字符,如'+'、''、'-',则将其删除并格式化。