Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMS format differs when launched using SMS launcher on android 9 and 10 #73717

Closed
cntoss opened this issue Jan 11, 2021 · 7 comments · Fixed by flutter/plugins#3817
Closed

SMS format differs when launched using SMS launcher on android 9 and 10 #73717

cntoss opened this issue Jan 11, 2021 · 7 comments · Fixed by flutter/plugins#3817
Assignees
Labels
found in release: 1.22 Found to occur in 1.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically

Comments

@cntoss
Copy link

cntoss commented Jan 11, 2021

While sending sms from url_launcher package. SMS output is not symmetric on android 10 and 9 below is my code

Result in android 9: Message: Hello Developer Welcome

Result in android 10: Message: Hello+Developer+Welcome

void sendSMS() async {
  String message = 'Hello+Developer+Welcome';
  String scheme = 'sms:7005?body=${Uri.encodeFull('Message: $message')}';
  if (await canLaunch(scheme)) {
    await launch(scheme);
  } else {
    print('problem on launcher');
  }
 }

Alternatively
If I replaced '+' symbol by '%2B' then result was changed
Result in android 9: Message: Hello+Developer+Welcome

Result in android 10: Message: Hello Developer Welcome

Below is code

    void sendSMS() async {
    String message = 'Hello+Developer+Welcome';
    String mesWithoutPlus = message.replaceAll('+', '\%2B');
    String scheme =
        'sms:7005?body=${Uri.encodeFull('Message: $mesWithoutPlus')}';
    if (await canLaunch(scheme)) {
      await launch(scheme);
    } else {
      print('problem on launcher');
    }
  }

Android 9
9
Android 10
10

@darshankawar
Copy link
Member

Issue reproducible using latest stable version.

  1. Android 11:

Screenshot 2021-01-12 at 1 52 32 PM

  1. Android 8:

Screenshot 2021-01-12 at 1 52 32 PM

  1. Android 9:

Screenshot 2021-01-12 at 2 00 04 PM

flutter doctor -v
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-IN)
    • Flutter version 1.22.5 at /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
    • Engine revision ae90085a84
    • Dart version 2.10.4

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.9.3

[!] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.52.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (3 available)
    • SM A260G (mobile)                   • 5200763ebcfa861f
      • android-arm • Android 8.1.0 (API 27)
    • sdk gphone x86 64 arm64 (mobile)    • emulator-5554
      • android-x64 • Android 11 (API 30) (emulator)
    • iPhone SE (2nd generation) (mobile) • 6C85835D-FBFD-4AB3-8DE8-B4FAD35E5367
      • ios         • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)

! Doctor found issues in 1 category.
dhs@Dhss-MacBook-Pro ~ % flutter doctor -v
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-IN)
    • Flutter version 1.22.5 at /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
    • Engine revision ae90085a84
    • Dart version 2.10.4

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.9.3

[!] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.52.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (3 available)
    • SM A260G (mobile)                   • 5200763ebcfa861f
      • android-arm • Android 8.1.0 (API 27)
    • AOSP on IA Emulator (mobile)        • emulator-5556
      • android-x86 • Android 9 (API 28) (emulator)
    • iPhone SE (2nd generation) (mobile) • 6C85835D-FBFD-4AB3-8DE8-B4FAD35E5367
      • ios         • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)

! Doctor found issues in 1 category.

@darshankawar darshankawar added found in release: 1.22 Found to occur in 1.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: first party p: url_launcher Plugin to launch external applications platform-android Android applications specifically labels Jan 12, 2021
@darshankawar darshankawar changed the title SMS launcher did not work same on android 9 and 10 SMS format differs when launched using SMS launcher on android 9 and 10 Jan 12, 2021
@cntoss
Copy link
Author

cntoss commented Feb 10, 2021

Temporary fixed:

    var androidInfo = await DeviceInfoPlugin().androidInfo;
    var release = androidInfo.version.release;
    if (release != '10') {
      scheme= scheme.replaceAll('+', '\%2B');
    }

@stuartmorgan stuartmorgan added documentation P2 Important issues not at the top of the work list labels Apr 8, 2021
@stuartmorgan
Copy link
Contributor

See dart-lang/sdk#43838 for more discussion. We need to update the docs to flag this since it's happening for several common schemes on recent versions of Android.

@d9media
Copy link

d9media commented Apr 13, 2021

Temporary fixed:

    var androidInfo = await DeviceInfoPlugin().androidInfo;
    var release = androidInfo.version.release;
    if (release != '10') {
      scheme= scheme.replaceAll('+', '\%2B');
    }

This didn't work for us in IOS.

Here's what did:


final String _emailUriString = _emailLaunchUri
                                .toString()
                                .replaceAll('+', '\%20');


%2B is enconding + not space according to RFC 3986.

EDIT: This worked in Android as well (Gmail).

@stuartmorgan
Copy link
Contributor

For SMS, for now the safest and simplest approach would be encodeComponent. E.g.,:

String message = 'Your SMS message body here';
String urlString = 'sms:7005?body=${Uri.encodeComponent(message)}';

(encodeFull is not intended for individual components, so the original code in this issue wasn't correct.)

@stuartmorgan
Copy link
Contributor

In general (e.g. for mailto) see dart-lang/sdk#43838 (comment) for a safer workaround for now than a replaceAll; the url_launcher README will be updated accordingly, likely with a utility method for this added to the API surface.

@stuartmorgan stuartmorgan self-assigned this Apr 20, 2021
stuartmorgan added a commit to stuartmorgan/plugins that referenced this issue Apr 21, 2021
`Uri`'s constructor doesn't handle query parameters correctly for
non-http(s) schemes, so the `mailto` example in the README is
misleading. This adds a new utility method to do query string
construction correctly, and updates the README to show using it and
warning about the need to use it in general.

If/when `Uri` is fixed to handle generic URI query parameters correctly,
this utility method can be deprecated.

Fixes flutter/flutter#75552
Fixes flutter/flutter#73717
stuartmorgan added a commit to stuartmorgan/plugins that referenced this issue Apr 21, 2021
`Uri`'s constructor doesn't handle query parameters correctly for
non-http(s) schemes, so the `mailto` example in the README is
misleading. This adds a new utility method to do query string
construction correctly, and updates the README to show using it and
warning about the need to use it in general.

If/when `Uri` is fixed to handle generic URI query parameters correctly,
this utility method can be deprecated.

Fixes flutter/flutter#75552
Fixes flutter/flutter#73717
stuartmorgan added a commit to flutter/plugins that referenced this issue Jun 16, 2021
`Uri`'s constructor doesn't handle query parameters correctly for
non-http(s) schemes, so the `mailto` example in the README is
misleading. This updates the README to show using a simple method
to work around that bug, and a warning about the need to use it.

Fixes flutter/flutter#75552
Fixes flutter/flutter#73717
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this issue Sep 13, 2021
`Uri`'s constructor doesn't handle query parameters correctly for
non-http(s) schemes, so the `mailto` example in the README is
misleading. This updates the README to show using a simple method
to work around that bug, and a warning about the need to use it.

Fixes flutter/flutter#75552
Fixes flutter/flutter#73717
henkibro pushed a commit to henkibro/url_launcher that referenced this issue Mar 1, 2022
`Uri`'s constructor doesn't handle query parameters correctly for
non-http(s) schemes, so the `mailto` example in the README is
misleading. This updates the README to show using a simple method
to work around that bug, and a warning about the need to use it.

Fixes flutter/flutter#75552
Fixes flutter/flutter#73717
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
found in release: 1.22 Found to occur in 1.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants