Home > Software design >  Why Doesn't Work This Package On Flutter?
Why Doesn't Work This Package On Flutter?

Time:07-31

I want to use url_launcher package but this package clearly run on Android 11 virtual device but Doesn't work real Android 11 and Android 12 devices, but it works on 9 and 7,

Here 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 is here 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 :)

CodePudding user response:

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

CodePudding user response:

For sending the whatsapp message using your code, I hope you might have already read Readme.md section for url_launcher and have already configured the url scheme as described there.

After the readme android & iOS configuration check, if your code is not working then check for,

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

So, check that your $whatsapp number is in format like 911234567890, if your phone number does contain any kind of special characters like, ' ', ' ', '-' then remove it and format it.

  • Related