Chat on Messenger option not working in webview flutter - flutter

I have a site that contains a Facebook Messenger API that works on browsers, but it does not work in Flutter WebView !
i tried to use url_launcher using this Code :
await launch(
request.url,
forceWebView: true,
enableJavaScript: true,
);
also i tried to play around settings in launch by updating some option like chenging forceWebView: true but it is not working !
output error :
PlatformException (PlatformException(ACTIVITY_NOT_FOUND, No Activity found to handle intent { intent://user/100272608460963/?intent_trigger=mme&ref=__chat_plugin_automation_ref_&nav=discover&source=customer_chat_plugin&source_id=1507329&metadata=%7B%22referer_uri%22%3A%22https%3A%5C%2F%5C%2Ffarmasi-iq.net%5C%2Fdemo%5C%2F%22%7D#Intent;scheme=fb-messenger;package=com.facebook.orca;end }, null, null))
the URL that contain the Messenger Plug-In so you can try it , it is working in any browser apps but not in WebView !
The error Happen when Pressing this black button , The user must be transferred to the Messenger application

Related

Opening Google calendar from Flutter app (Deep Linking)

I want to open Google calendar app more specifically the create event page in the app from my another flutter app.
I am using the URL launcher package but it opens the app in chrome
What change should I make in the URL so that the add event page opens directly in the google calendar app.
Currently my URL looks like below
https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda
My code for that part is as below
if (await canLaunchUrl(Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda'))) {
await launchUrl(
Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda'),
mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch URL';
}
rathe than using a HTTP request, you could use googleapis package from https://pub.dev which has inbuilt methods to create Google Calender events directly within the Calender app.
Check package and documentation here.
Happy coding!

Send text to Viber and Facebook Messenger with Flutter

How can I send a text directly to a specific phone number on Viber? or to a specific person on Facebook messenger?
with whatsapp I'm using url_launcher with whatsapp with below code, and it is working fine.
var whatsapp_url = "whatsapp://send?phone=" + whatsapp_number + "&text=hellooo";
try {
await launchUrl(Uri.parse(whatsapp_url));
} catch (e) {
print('could not launch whatsapp');
}
I tried using the same package with Viber using ("viber://chat?number=") and Facebook messenger using ('m.me/username') but both are just opening a web site and not opening the mobile App and not finding the phone number or the messenger chat.
I need to do a similar thing by clicking an IconButton to open a specific chat on Viber and another IconButton to open a specific Facebook messenger chat.
I found a solution in case someone needed - I used the same url_launcher library.
Viber:
var viber_link = "viber://chat/?number=$Country_Code$Mobile_Number&draft=$Message_to_be_sen”
;
Viber doesn’t need ‘+’ sign when writing the country code
Facebook Messenger:
var facebook_messenger_link = 'https://m.me/$FaceBook_Name?text=$Message_to_be_sent;
Facebook Name can be found by clicking on the profile picture on Facebook and checking the URL, it comes after ‘https://www.facebook.com/{FB_Name}’
Telegram:
var telegram_link = 'https://t.me/+$Country_Code$Mobile_Number&draft=$Message_to_be_sen';
Telegram needs the ‘+’ sign when writing the country code
Then used this code for launching it:
final Uri app_link_uri = Uri.parse(app_link);
try {
await launchUrl(
app_link_uri,
mode: LaunchMode.externalApplication,
);
} catch (error) {
print(‘error’ catching: $error);
}

Problem with Webview showing Google Photos in Flutter

I am using flutter_webview_plugin: ^0.3.11
This is my code
Widget build(BuildContext context){
return WebviewScaffold(
url: glbPhotoURL,
withJavascript: true,
scrollBar : true,
withZoom: true
)
url: glbPhotoURL => here glbPhotoURL is a URL that I am passing
When I am using any normal URL it is running fine (like http://www.google.com, http://youtube.com"
Even url like - https://youtu.be/o5UPfG1eIw4 is running fine
But when I am using any google photo url (short url) it is throwing an error net::ERR_UNKNOWN_URL_SCHEME for eg - https://photos.app.goo.gl/FkQenAD8kQQc4TSr6
If I am using the expanded URL it shows the pictures -https://photos.google.com/share/AF1QipNItZG3Cg_hn9__2QnuVh3nNMbRuGxQaQSWZ76qni7L7h0ORbauolcH3AKe0MOnEA?
key=emc1Mk1CenRJRjloMjV5V1AzcmczNUprcGFsbmR3
Please help me resolve the issue
As of now I am running it on Android physical device.
Google Photos uses Firebase Dynamic Links. I suggest launching the link externally. I encountered a similar error on Android before, when Firebase Dynamic Links are being forced to be loaded in a WebView. FDLs are expected to be handled by Google Play Services in Android. But since the WebView doesn't know what to do with the link it's forced to display, the WebView returns "net::ERR_UNKNOWN_URL_SCHEME" error.
Open the link externally by using url_launcher. Use RegEx to filter intent URLs and check if the URL can be launched and be handled externally (outside the app).
var yourURL = "URL goes here";
// Check if URL contains Google Photos URL
yourURL.contains(RegExp('^https://photos\.app\.goo\.gl/.*$')){
// Check if the URL can be launched
if (await canLaunch(yourURL)) {
await launch(yourURL);
} else {
print('Could not launch $yourURL');
}
}

flutter_webview_plugin: how to open a link in default browser

I use flutter_webview_plugin and I would like to open a link; not in my webview, but in the browser of the user. When I use StreamSubscription with String, the app listens only to the url from the app, like when I use FlutterWebViewPlugin().reloadUrl or .launchUrl.
You should be able to use the url_launcher package concurrently with the flutter_webview_plugin to get your desired effect.
Basically with the webview, you can use the parameter invalidUrlRegex in either launch or the WebviewScaffold to setup URLs not allowed to be opened inside your webview.
eg: below blocks any links that dont have the host google or stackoverflow.
invalidUrlRegex: r'^(?!https:\/{2}www\.google\.com|https:\/{2}stackoverflow\.com).*$'
Then have an onStateChanged listener on the webview, this will cause any blocked URLs to result in a WebViewState.abortLoad state.
FlutterWebviewPlugin().onStateChanged.listen(onStateChanged);
onStateChanged(WebViewStateChanged change) {
if (change.type == WebViewState.abortLoad) {
canLaunch(change.url).then((val) => val ? launch(change.url) : null);
}
}
The above will use the url_launcher to launch the URL in the user's preferred browser.
This is by far the best approach that I was able to come up within our application.

Facebook messenger extension js doesnt load when there is adsense code

I am having a webview for my facebook messenger bot , but i am putting a google adsense ad inside the webview. However , there is a problem that when I am putting the ad , messenger extensions isn't calling the function
<script>
window.extAsyncInit = function() {
// the Messenger Extensions JS SDK is done loading
};
</script>
although i am doing everything as per the documentation . I don't know whats the issue of google adsense , is it stopping the async process inside the page ?
window.extAsyncInit will not fire when messenger_extensions is false.
Property messenger_extensions must be true if using Messenger Extensions.
https://developers.facebook.com/docs/messenger-platform/send-api-reference/url-button
"buttons":[
{
"messenger_extensions": true,
"type":"web_url",
"url":"https://petersfancyapparel.com/criteria_selector",
"title":"Select Criteria",
"webview_height_ratio": "full",
"fallback_url": "https://petersfancyapparel.com/fallback"
}
]