Is there any way to specify facebook-links with the HTTP protocol which opens the app (iPhone/Androdi) if installed? - facebook

So I know the Facebook-app supports the fb:// URL scheme. But does it also support a URL scheme for HTTP?
I've tried for instance https://www.facebook.com/Google, and it does not yield an option to open the app, when clicked on from Chrome on an HTC One M8 device. So obviously Facebook haven't defined a URL scheme to match that URL. But they might have created others? Theoretically they could for instance have a scheme that triggered when a sub-url contains /app or something.
My goal is to link to a Facebook profile page which opens in the app if it is installed, and in the browser if not. Without using any Javascript. If facebook have defined a schema matching any HTTP-protocol, it is possible.

I made this work for link to google play with this function, changing te protocol to the facebook could work
public void getpro(View view) {
final String appName = BuildConfig.APPLICATION_ID;
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName")));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName")));
}
}
to:
public void getpro(View view) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("facebook://facebook.com/inbox")));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com")));
}
}

You can try to achieve this with Intents. I found this:
String uri = "facebook://facebook.com/inbox";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Intent is used to call other applications while using an application.

Related

How to open subscriptions page in Play Store in Flutter

I want to edit my active subscription and for this I need to go to the play store.
Forcing the user to open the play store first, and then go to the settings page, and then open subscriptions is not suitable. Can this be done somehow in 1 click (not in browser)?
Options with opening in the browser are not suitable. I need to open the page with all subscriptions (https://play.google.com/store/account/subscriptions)
I need a redirect link market://...
Thank you!
I tried next packages: url_launcher, store_redirect etc.
Methods like: `
final Uri url =
Uri.parse('https://apps.apple.com/app/MyAppName/idXXXXX');
try {
if (await canLaunch(url.toString())) {
await launch(url.toString());
} else {
throw 'Could not launch $url';
}
} catch (e) {
print(e);
}
and
launchUrl(Uri.parse('https://play.google.com/store/account/subscriptions?sku=pro.monthly.testsku&package=com.example.app'));
I had to use only this method:
final url = Uri.parse('http://play.google.com/store/account/subscriptions');

Sharing screenshot with text to facebook unity

I'm trying to give the user the possibility to post a screenshot of his game on facebook with the dowload link of the game.
I've looked a bit and it seemed it would be possible with FB.API, but I can't manage to make it work.
Aparently you need a permission but I can't to find which permission and how to give it.
I'm using unity 2020.3.21f1
Here is what I'm doing for now
public void ShareScreenShot(Texture2D screenShot)
{
byte[] encodedScreenShot = screenShot.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", encodedScreenShot, "ScreenShot.png");
wwwForm.AddField("message", "Venez me défier : https://randomlink.blablabla");
FB.API("me/photos", HttpMethod.POST, ShareScreenShotCallback, wwwForm);
}
void ShareScreenShotCallback(IResult result)
{
if (result.Error != null)
{
Debug.Log(result.Error);
}
else
{
Debug.Log("sharing success");
}
}
If anyone of you knows how it can be done, it would be of great help, thanks
I suppose you need to login to facebook with custom permissions, because the default one only allows you to send invitations to choosen friends.
https://developers.facebook.com/docs/unity/reference/current/FB.LogInWithPublishPermissions/

Flutter open whatsapp with text message

I want to open whatsapp from my Flutter application and send a specific text string. I'll select who I send it to when I'm in whatsapp.
After making some research I came up with this:
_launchWhatsapp() async {
const url = "https://wa.me/?text=Hey buddy, try this super cool new app!";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Which works ok ish, however there are two problems:
As soon as I make the text string into multi words it fails. So if I change it to:
_launchWhatsapp() async {
const url = "https://wa.me/?text=Hey buddy, try this super cool new app!";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Then the Could not launch $url is thrown.
I have whatsapp already installed on my phone, but it doesn't go directly to the app, instead it gives me a webpage first and the option to open the app.
Here is the webpage that I see:
Any help on resolving either of these issues would be greatly appreciated.
Thanks
Carson
P.s. I'm using the Url_launcher package to do this.
From the official Whatsapp FAQ, you can see that using "Universal links are the preferred method of linking to a WhatsApp account".
So in your code, the url string should be:
const url = "https://wa.me/?text=YourTextHere";
If the user has Whatsapp installed in his phone, this link will open it directly. That should solve the problem of opening a webpage first.
For the problem of not being able to send multi-word messages, that's because you need to encode your message as a URL. Thats stated in the documentation aswell:
URL-encodedtext is the URL-encoded pre-filled message.
So, in order to url-encode your message in Dart, you can do it as follows:
const url = "https://wa.me/?text=Your Message here";
var encoded = Uri.encodeFull(url);
As seen in the Dart Language tour.
Please note that in your example-code you have put an extra set of single quotes around the text-message, which you shouldn't.
Edit:
Another option also presented in the Whatsapp FAQ is to directly use the Whatsapp Scheme. If you want to try that, you can use the following url:
const url = "whatsapp://send?text=Hello World!"
Please also note that if you are testing in iOS9 or greater, the Apple Documentation states:
Important
If your app is linked on or after iOS 9.0, you must declare the URL schemes you pass to this method by adding the LSApplicationQueriesSchemes key to your app's Info.plist file. This method always returns false for undeclared schemes, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.
So you need to add the following keys to your info.plist, in case you are using the custom whatsapp scheme:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
till date: 27-06-2022
using package: https://pub.dev/packages/url_launcher
dependencies - url_launcher: ^6.1.2
TextButton(
onPressed: () {
_launchWhatsapp();
},
)
_launchWhatsapp() async {
var whatsapp = "+91XXXXXXXXXX";
var whatsappAndroid =Uri.parse("whatsapp://send?phone=$whatsapp&text=hello");
if (await canLaunchUrl(whatsappAndroid)) {
await launchUrl(whatsappAndroid);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("WhatsApp is not installed on the device"),
),
);
}
}
Here is new update way...
whatsapp() async{
var contact = "+880123232333";
var androidUrl = "whatsapp://send?phone=$contact&text=Hi, I need some help";
var iosUrl = "https://wa.me/$contact?text=${Uri.parse('Hi, I need some help')}";
try{
if(Platform.isIOS){
await launchUrl(Uri.parse(iosUrl));
}
else{
await launchUrl(Uri.parse(androidUrl));
}
} on Exception{
EasyLoading.showError('WhatsApp is not installed.');
}
}
and call whatsapp function in onpress or ontap function
For using the wa.me domain, make sure to use this format...
https://wa.me/123?text=Your Message here
This will send to the phone number 123. Otherwise, you will get an error message (see? https://wa.me/?text=YourMessageHere ). Or, if you don't want to include the phone number, try this...
https://api.whatsapp.com/send?text=Hello there!
Remember, wa.me requires a phone number, whereas api.whatsapp.com does not. Hope this helps!
I know it is too late for answering this, but for those who want the same functionality, the current way is to do it like this:
launchUrl(Uri.parse('https://wa.me/$countryCode$contactNo?text=Hi'),
mode: LaunchMode.externalApplication);
if you will use URL Launcher then the whatsapp link will be open on web browser. So you need to set parameter - not to open on safari browser. The complete code you can find on this flutter tutorial.
But for your case use below code.
await launch(whatappURL, forceSafariVC: false);
Today i am adding solution its working fine on my desktop and phone
Add 91 if your country code is +91
Remember not add any http or https prefix otherwise wont work.
whatsapp://send?phone=9112345678&text=Hello%20World!

Logging out from facebook using facebook c# sdk in WP7

I want to implement logout from facebook using facebook C# sdk in my windows phone app
My primary question is how do we logout using Facebook C# SDK in WP7
I found this article in search
Article link
there he is trying to find the logout url using regex, but that did not working in my app
when i try that the browser navigated event is going into infinite loop
you can share any samples/posts related to facebook logout in windows phone 7.
I want logout should happen with out user intervention, after he clicks on a button he should looged out from facebook and from next time he should see the login page
I tried following posts/blogs also but no use.
LINK 1
LINK 2 this giving error while splitting the accesstoken
UPDATE
LogOutButtonCode
FacebookClient _fbClient = new FacebookClient(fbaccess.AccessToken);
var logoutParams = new Dictionary<string, object>();
logoutParams.Add("next", "https://www.facebook.com/connect/login_success.html");
//logoutParams.Add("",)
var logoutUrl = _fbClient.GetLogoutUrl(logoutParams);
BrowserControl.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(BrowserControl_Navigated);
BrowserControl.Navigate(new Uri(logoutUrl.AbsoluteUri));
Navigated Event CODE
if (e.Uri.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
e.Uri.AbsoluteUri returns https://www.facebook.com/home.php
Logout URL i am getting from the server https://www.facebook.com/logout.php?next=https://www.facebook.com/connect/login_success.html
Use FacebookClient.Logout to generate the logout url.
This is the snippet from winforms sample which will work in wp7 with some modifications.
private void btnLogout_Click(object sender, EventArgs e)
{
var fb = new FacebookClient();
var logoutUrl = fb.GetLogoutUrl(new
{
next = "https://www.facebook.com/connect/login_success.html",
access_token = _accessToken
});
var webBrowser = new WebBrowser();
webBrowser.Navigated += (o, args) =>
{
if (args.Url.AbsoluteUri == "https://www.facebook.com/connect/login_success.html")
Close();
};
webBrowser.Navigate(logoutUrl.AbsoluteUri);
}
Make sure to persist the access token somewhere when you login as it is required to logout.

open mp3 or apk file from webview

I would like to know how I can open a Mp3 file from within a webview, basically a link that points to an MP3 file which would then open up the standard media player. Is this possible? I know it is because it works on the default webbrowser so I was wondering why I can't get it to work on a standard webview. Any help would be much appreciated.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".mp3")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "audio/*");
view.getContext().startActivity(intent);
return true;
} else if (url.endsWith(".mp4") || url.endsWith(".3gp")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "video/*");
view.getContext().startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
}
}
Robbe's answer is correct, however I ran into some headaches implementing this functionality, so you should note that you must be passing a DIRECT LINK to an mp3, it can't be a magical URL that ends up at an mp3 after several redirects, the loading wheel will spin and you will be prompted with a "Can not play the requested stream" message.