Issue
I want to use the url_launcher
package. This package clearly runs on Android 11 virtual device but doesn't work on real Android 11 and Android 12 devices. However, it works on 9 and 7.
Here is my build.gradle
configs
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
}
And here is the code block
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"),
),
);
}
}
Thank you so much :)
Solution
Add any URL schemes passed to canLaunchUrl as entries in your AndroidManifest.xml, otherwise it will return false in most cases starting on Android 11 (API 30) or higher. A element must be added to your manifest as a child of the root element.
<!-- 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>
Please look at the pub config: https://pub.dev/packages/url_launcher
Answered By - Mohamad Alzabibi
Answer Checked By - Senaida (JavaFixing Volunteer)