Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to launch the gmail app when a user taps on a button in my application. I am using the URL launcher package. Right now, I am testing on android and when I launch URLs for youtube or spotify, the app launches. However, when I try to launch gmail through a gmail url, it is not working.
Here is the URL that I am using: "https://mail.google.com/mail/u/0/#search/thisisasearch". Instead of launching to the app, it launches to the browser. Can anyone help me figure this one out?
Also if anyone knows how to implement this on iOS, that would be greatly appreciated!
To open default mail of the application you can use below code
_sendMail() async {
// Android and iOS
const uri =
'mailto:test#example.org?subject=Greetings&body=Hello%20World';
if (await canLaunch(uri)) {
await launch(uri);
} else {
throw 'Could not launch $uri';
}
}
you can send URI as below for different operations as well apart from mail
For Call - 'tel:+phonenumber'
For SMS - 'sms:+phonenumber'
you can use flutter_appavailability library
Import below packages:
import 'dart:io';
import 'package:flutter_appavailability/flutter_appavailability.dart';
Use below method:
void openEmailApp(BuildContext context){
try{
AppAvailability.launchApp(Platform.isIOS ? "message://" : "com.google.android.gm").then((_) {
print("App Email launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("App Email not found!")
));
print(err);
});
} catch(e) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text("Email App not found!")));
}
}
look : Reference
Related
I just released my first app and It has a button in it that takes you to a website.
A user just sent me this:.
I tried googling Google's secure browsers policy but not much info is coming up.
how can I make my app comply with this policy? I think the button opens a browser in app (I use duckduckgo as my default browser and haven't had an issue)
is it just a case of opening a browser and then heading to the website when the button is pressed?
my code to open the website is:
_launchURL() async {
const url = 'https://www.thiswebsite.com';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
}
thanks so much and any help would be greatly appreciated
Google is trying to make sure, you open this window in an actual new browser window, not in a webview still under the control of your application.
Your code should open an external browser.
Maybe the user has no browser installed on their device? Maybe their default browser is some exotic thing not recognized by Google?
If you are using the latest version of url_launcher (currently 6.1.8) there is not a lot more you can do.
You could force the app to take the external browser, not the in-app webview:
await launchUrl(_url,mode: LaunchMode.externalApplication);
But that should be what happens anyway. If your version is up to date, ask your user, what browser they use. Be prepared to tell them that they need to use another one.
Sorry to ask this here but couldnt find any information related to this online. In native java I have used intent to select com.whatsapp.w4b and com.whatsapp.
I cant figure out how to do it with dart. So far I know:
String androidUrl = 'https://wa.me/$recipientMobile/?text=${Uri.parse(message)}';
String iosUrl = 'https://api.whatsapp.com/send?phone=$recipientMobile=${Uri.parse(message)}';
if (Platform.isAndroid) {
await launch(androidUrl);
} else if (Platform.isIOS) {
if(await canLaunch(iosUrl)){
await launch(iosUrl);
} else {
showToast('Error! Try again.', 'Short');
}
}
This code works but only launches default WhatsApp. How to launch bussiness / personal whatsapp?
Thanks in advance.
EITHER you'll have to ask the users to change the defaults in the link settings of the phone as suggested here.
OR you'll have to share a link that they paste in the browser which will open the app selection section of the phone with both the options, as shown here.
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 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
I am trying to user gmail api. Google is asking me to make a video with demo of Oauth consent screen.
While searching in the internet I have found solutions for web and native android android. The docs of flutter packages googleapi and googleapi_auth were not very helful. If anyone has already implemented any suggestions would be helpful.
It's probably too late but here is the code for
' clientViaUserConsent(_clientid, _scopes, userPrompt)
.then((AuthClient client) {
//your code to authenticate any of your google platform
}
Here is the userPrompt function
void userPrompt(String url) async {
if (await canLaunch(url)) {
print("Launching url");
launch(url);
} else {
print("unable to launch the url");
}}
So whenever the clientviauserprompt is called the prompt function will launch the url to the default browser for the user consent.
You have to use urllauncher dependency for this.