url_launcher helps to draft an email, make a call and send a sms to a specific recipient. Is there any way to launch mail/sms apps (inbox - not draft) ?
I'm not sure if you can do that in iOS but for Android, use android_intent plugin and put the appropriate package_name in data.
if (platform.isAndroid) {
AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: 'package:com.example.app',
);
await intent.launch();
}
Related
I would like to create an app in Flutter. The web version contains a button that should open version of android or IOS app according user platform if mobile version of app was installed (like an app install or open banner).
How should I detect is app installed in web flutter?
update:
I tried below code using import 'package:universal_html/html.dart' pakage:
window.location.href = (defaultTargetPlatform ==
TargetPlatform.android)
? 'https://play.google.com/store/apps/details?id=com.amazon.mShop.android.shopping'
: 'https://apps.apple.com/us/app/amazon-shopping/id297606951';
But this just open the store. I'm looking for a solution to open app directly if it was installed.
If this is fine for you, you can use an URL launcher. This way it opens the App store or play store and the user can either download the App or open it.
For Example flutter has a package that does most of this work:
https://github.com/Purus/launch_review
LaunchReview.launch(androidAppId: "yourpackagename", iOSAppId: "appid");
You just need to pass your package name and on ios your app ID
You could also use an URL Launcher:
https://pub.dev/packages/url_launcher
The code would be similar to this:
_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
}
else {
throw 'Could not launch $url';
}
}
URL Example
try {
launch("market://details?id=" + appPackageName);
} on PlatformException catch(e) {
launch("https://play.google.com/store/apps/details?id=" + appPackageName);
} finally {
launch("https://play.google.com/store/apps/details?id=" + appPackageName);
}
Note this code needs to be adapted
Also see this tutorial for help: https://flutteragency.com/open-appstore-playstore-url-in-flutter/
Edit:
If you want to directly open another app you can use something like this:
https://pub.dev/packages/external_app_launcher/
flutter pub add external_app_launcher
The Code would look like this then:
await LaunchApp.openApp(
androidPackageName: 'net.pulsesecure.pulsesecure',
iosUrlScheme: 'pulsesecure://',
appStoreLink: 'itms-apps://itunes.apple.com/us/app/pulse secure/id945832041',// openStore: false
);
// Enter the package name of the App you want to open and for iOS add the URLscheme to the Info.plist file.
// The `openStore` argument decides whether the app redirects to PlayStore or AppStore.
// For testing purpose you can enter com.instagram.android
More infos regarding implementation and additional setup infos you can find here: https://pub.dev/packages/external_app_launcher in the Readme
I am currently looking for ways to send an email from flutter desktop. any one knows how I can do this?
flutter_email_sender: ^5.0.2 has support for only iOS and android .
I am building a desktop app that collects users inputs and generates a receipt pdf from it. I want to send the pdf file to my email
You can use url_launcher package to send email
final Uri params = Uri(
scheme: 'mailto',
path: 'example#gmail.com',
query: encodeQueryParameters(<String, String>{
'subject': 'Your subject goes here'
}),
);
var url = params.toString();
await launch(url);
This way it'll work in all platforms
I have this code:
import 'package:url_launcher/url_launcher.dart';
...
await launch("https://example.org/bigprizes");
It launches a web view within the app on iOS. Instead, I want it to launch in Safari or some other external browser of the user's choice. Is there a way to do that in Flutter?
Look at Step 4 in https://www.digitalocean.com/community/tutorials/flutter-url-launcher
await launch("https://example.org/bigprizes", forceSafariVC: false);
url_launcher plugin (https://pub.dev/packages/url_launcher) has methods launchUrl() and launchUrlString() which both has a property mode where you can specify how the app will open the URL. More details on the Launch mode documentation
Basically you can call it like this:
static Future<void> launchURL(String url) async {
if (await canLaunchUrlString(url)) {
// Passes the URL to the OS to be handled by another application.
await launchUrlString(url, mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch $url';
}
}
check this package https://pub.dev/packages/flutter_linkify it's may be useful for your project
mailto:<email address>?subject=<subject>&body=<body>
This one creates an email. I want to just open the Gmail app (inbox) with url_launcher package.
Is it possible?
You can simple use
launch("https://mail.google.com/mail/u/0/#inbox")
This will open the inbox
You can use external dependency to open any app or playstore directly.
https://pub.dev/packages/external_app_launcher
Yes, it is possible with the url_launcher package.
To open the gmail app (inbox) with pre-filled mailto, subject and body, you can do something like this:
final Uri params = Uri(
scheme: 'mailto',
path: 'mailto#gmail.com',
query: 'subject=This is the subject&body=this is body',
);
final url = params.toString();
launch(url);
I want to make the container click lead to a specific youtube url which should open in the the youtube app and not in webview inside the app.
add in pubspec.yaml:
dependecies:
url_launcher: ^5.4.2
add this in your code:
LaunchUrl('https://www.youtube.com');//or any link you want
You should look into the package android_intent. Basically it will resolve the url if it has been defined as a valid link for an application in your android parameters (which is enabled by default for youtube).
Code Sample
AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: url,
);
await intent.launch();
you can use package url_launcher with the function below:
launchUrl(
Uri.parse("http://www.youtube.com/watch?v=${youtubeID}"),
mode: LaunchMode.externalApplication);