Facebook's Sharing on Android documentation tells us to show the ShareDialog with the following code snippet:
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription(
"The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}
My question is why do we need to check ShareDialog.canShow()? In what scenarios would this possibly return false and do we need to handle this scenario? The example code would just fail silently not tell the user anything.
I spent a lot of time yesterday trying to debug an error related to this. Facebook's docs are poor in this sense and when there is an error related to this canShow() method, it just fails silently, no logging at all.
So, to answer your question:
My question is why do we need to check ShareDialog.canShow()? In what
scenarios would this possibly return false and do we need to handle
this scenario?
Based on the scenario I faced: when the user doesn't have the Facebook app installed on their device and you want to share photos (SharePhotoContent) or videos (ShareVideoContent), canShow() will return false. The reason is that Facebook SDK's WebView version doesn't support sharing this kind of content.
I found this out debugging their FacebookActivity class, on the handlePassThroughError() method. The (not logged) error message is:
"Unable to show the provided content. This typically means that the Facebook app is not installed or up to date. If showing via the Web, this could mean that the content has properties that are not supported via this channel."
So, what should we do when canShow() returns false?
It depends on your scenario. Possible solutions would be:
Show a dialog (or SnackBar) telling the user that they need to install the Facebook app to be able to share this kind of content;
Request an authentication token, log the user using the Facebook SDK, and share the content using your own dialog and calling Facebook API directly.
Possible solutions for Facebook would be include this on their documentation or log this error on LogCat.
Hope it helps!
this answer for someone facing the same problem.
#leocadiotine was great.
From the facebook sdk sample, when the ShareDialog.canShow() return false you should use ShareApi.share function.
In AndroidManifest.xml, add:
<queries>
<provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
</queries>
// for facebook
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
});
Related
I am really wasting time on trying to figure out what might be wrong. I have a button(not fb send button) and on click i want to open messenger(or with any other way) to send a message to users. This is my code:
MessageDialog messageDialog = new MessageDialog(thisFragment);
if (MessageDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
messageDialog.show(linkContent);
}else{
Log.e(TAG, "Can't be shown");
}
I tried as many code sample as i could find on the internet. The facebook documentation on sharing is really poor.The code always executes the 'else' block on my if statement.
I can show the ShareDialog with the same exact procedure. But MessageDialog is not working and it doens't even logs anything. Is there any way to send a message? Or any source that is tested and working?
Thanks a lot
When using Firebase invites and accessing the dynamic links at the startup of the app on Android, is there a way to know whether the user just installed the app thanks to the invite or whether it was already installed?
Many thanks,
Borja
EDIT: Thanks to Catalin Morosan for the answer
It turns out that you can find this out using method AppInviteReferral.isOpenedFromPlayStore(result.getInvitationIntent()). In the activity that runs when you click on the invitation:
// Create an auto-managed GoogleApiClient with access to App Invites.
mGoogleApiClientInvite = new GoogleApiClient.Builder(this)
.addApi(AppInvite.API)
.enableAutoManage(this, this)
.build();
// Check for App Invite invitations and launch deep-link activity if possible.
// Requires that an Activity is registered in AndroidManifest.xml to handle
// deep-link URLs.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClientInvite, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract information from the intent
Intent intent = result.getInvitationIntent();
String invitationId = AppInviteReferral.getInvitationId(intent);
boolean alreadyUser = AppInviteReferral.isOpenedFromPlayStore(result.getInvitationIntent());
if (alreadyUser) {
// Do stuff...
} else {
// Do other stuff...
}
}
}
});
Based on this Google product form post, the Firebase Dynamic Links library will only check for incoming deep links once per app lifetime, meaning you'd need to uninstall and reinstall the app for it to check again. This feeds into the behavior of the getInvitation() method, and it appears you can imply whether the app was previously installed based on the results of this method.
To me, this seems awfully confusing. At Branch.io we do it completely differently: your link data object will always contain an is_first_session boolean, which you can programmatically handle in any way you choose.
I'm using dynamic links for my app.
I've followed the tutorial step-by-step and I'm able to open the app by clicking on the link posted on facebook.
But when I invoke getInvitation, I always have CANCELED as status of AppInviteInvitationResult.
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, false).setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
// [END_EXCLUDE]
} else {
Log.d("StartActivity", "getInvitation: no deep link found.");
}
}
});
Into debug, I can see that result.getStatus() returns CANCELED, but the click on lick open the app correctly.
Where I'm wrong?
EDIT: The link that I'm using is:
https://wft4z.app.goo.gl/?link=https://aqld.it/testlink/112972&al=aqld://test/about?params%3D17363&apn=com.project.mydeeplink
The filter on manifest:
The status is canceled when no intent has been received. I was wondering the same thing and it turned out that my links created in firebase web page were wrong. I wrote some ideas on how to debug the url problem as an answer to another question. If you have the same problem as I did, they should be helpful:
https://stackoverflow.com/a/37615175/4025606
Doesn't directly answer your question but you could eliminate badly formed urls as a root cause by using this page to create firebase dynamic links for both ios and Android: http://fdl-links.appspot.com/
Just double-check if you have added the SHA-1 in the firebase console and the added SHA-1 matches the SHA1 of the generated APK. I was seeing the same issue - result.getStatus() returning CANCELED prior to this, but after adding the SHA-1 on firebase console, it started working fine. :)
I have a text in my android application and I want the user to be able to click the FB Share button in the app and get this text posted on their own wall.
So far I've been following this tutorial:
https://developers.facebook.com/docs/android/share
and it is only good for either sharing a link (I dont want to share a link) or bringing up the share status dialog, but it is empty.
how can I populate that dialog with the text I want to populate it with?
this is my code
private void shareOnFacebook(String textToBeShared) {
if (FacebookDialog.canPresentShareDialog(a, FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(a).setCaption(textToBeShared).build();
a.uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
publishFeedDialog();
}
} // End of shareOnFacebook
I tried with setLink(null).setDescription, setName, setCaption but none of those worked.
The short answer is, you can't.
Prefilling the text is against Platform policies (see section 2.3 of https://developers.facebook.com/policy/), and as such, the Android SDK doesn't allow you to do it.
Hi Facebook Login: It doesn't redirect to the Facebook app installed ?
The user already had Facebook installed and he was logged in, no need to login facebook, in application already login in default facebook application. no need to login again how to solved this issue?
Any one have idea give me suggestion.
EDIT: is it possible to get user name and id to my application, default facebook account login to mobile?
Use latest facebook SDK.
Please also check that in your facebook sdk there is one java file with name Facebook.java
Just check authorize function in that class.
It should be like below:
public void authorize(Activity activity, String[] permissions,
int activityCode, final DialogListener listener) {
boolean singleSignOnStarted = false;
mAuthDialogListener = listener;
//THIS CODE IS EDITED BY SHREYASH FOR NOT ALLOW THE DEFAULT FACEBOOK APP
// Prefer single sign-on, where available.
if (activityCode >= 0) {
singleSignOnStarted = startSingleSignOn(activity, mAppId,
permissions, activityCode);
}
// Otherwise fall back to traditional dialog.
if (!singleSignOnStarted) {
startDialogAuth(activity, permissions);
}
}
Please check it. and let me know.
Hope it will help you a lot as it help me lot.
Enjoy Coding... :)