1

when i call launchUrl (url_launcher 6.2.2) it's not working or outstanding.

I want to open goole drive with link.

final Uri url = Uri.parse("googel drive link share all people have");     
bool res = await launchUrl(url);
if (!res) {throw Exception('Could not launch url');}
1
  • Define it's not working Commented Dec 20, 2023 at 10:12

2 Answers 2

0

Try this:

import 'package:url_launcher/url_launcher.dart';


final String googleDriveLink = "https://drive.google.com/your-link-here";
final Uri url = Uri.parse(googleDriveLink);

try {
  bool launched = await launch(url.toString());
  if (!launched) {
    throw 'Could not launch $url';
  }
} catch (e) {
  throw 'Error launching URL: $e';
}

Ensure that you have the url_launcher package added to your pubspec.yaml file:

dependencies:
  url_launcher: ^6.2.2
Sign up to request clarification or add additional context in comments.

1 Comment

it's not work for me....
0

url_launcher doesn’t always open drive links externally, because android/iOS need proper intent and visibility configuration.

Android

AndroidManifest.xml - Starting from API 30 Android requires, package visibility configuration in your AndroidManifest.xml

<queries>
  <!-- If your app opens https URLs -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
  <!-- If your app makes calls -->
  <intent>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
  </intent>
  <!-- If your sends SMS messages -->
  <intent>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="smsto" />
  </intent>
  <!-- If your app sends emails -->
  <intent>
    <action android:name="android.intent.action.SEND" />
    <data android:mimeType="*/*" />
  </intent>
</queries>

ios

Add URL schemes to your Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>https</string>
  <string>http</string>
</array>

Example

    if (url != null && await canLaunchUrl(Uri.parse(url))) {
      await launchUrl(
        Uri.parse(url),
        mode: LaunchMode.externalApplication,
      );
    } else {
      debugPrint('Could not launch URL: $url');
    }

Deps

url_launcher: ^6.3.2

If you still have any doubts, checkout the Documentation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.