How to create "Invite Friends" button in android? - android

I want open this type of window when I click "Invite Friends" button & after selecting any of them I wand paste the link for my app in the selected application

Try below code to share your link:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "YOUR_LINK");
sendIntent.setType("text/plain");
startActivity(sendIntent);

You can see complete example "How to Create Refer a friend Link"
You need to add Firebase Dynamic link(Firebase Invites depreciated now). Firebase Dymanic Link is build over Firebase Invites So you can see the invites dependency on gradle file.
There is Two ways to create "Refer a Friend Link"
Using Firebase base Dynamic Object
Manually Create Refer a Link
1) Option :-
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.example.com/"))
//.setDomainUriPrefix("https://example.page.link") // no longer in user please
.setDynamicLinkDomain("example.page.link") // use this code and don't use https:// here
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
// Open links with com.example.ios on iOS
.setIosParameters(new DynamicLink.IosParameters.Builder("com.example.ios").build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
2) Option:-
String sharelinktext = "https://referearnpro.page.link/?"+
"link=https://www.blueappsoftware.com/"+
"&apn="+ getPackageName()+
"&st="+"My Refer Link"+
"&sd="+"Reward Coins 20"+
"&si="+"https://www.blueappsoftware.com/logo-1.png";
Then Call ShortDynamicLink Object
Refer Link will be look like this :
https://referearnpro.page.link?apn=blueappsoftware.referearnpro&link=https%3A%2F%2Fwww.blueappsoftware.com%2F
You can check complete example here

Related

Trying to get the dynamic link that opened the app on Android 12 gives incomplete link

I am creating a share button for a post on the feed. I am generating a unique link using Firebase Dynamic Links with a custom parameter at the end. On Android 11 and previous devices, the link was successfully handled and I retrieved the complete link and then extracted the id part from it and then loaded the correct post data using that. But on Android 12, I only get the base part of my link and not the custom parameter that I added. I don't want to change the link generation logic, since the app is already on the Play Store. Can anybody help?
Link Generation Code:
String url = "https://<BASE LINK CONFIGURED IN FIREBASE>/?link=https://<BASE LINK CONFIGURED IN FIREBASE>/&apn=<APP PACKAGE NAME>&afl=<LINK TO APP IN GOOGLE PLAY STORE>&ofl=<LINK TO APP IN GOOGLE PLAY STORE>";
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(Uri.parse(url))
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortLink = task.getResult().getShortLink();
String link = shortLink.toString();
link += "?id=" + post.getID();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, link);
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
context.startActivity(shareIntent);
} else {
Toast.makeText(context, "Error creating link", Toast.LENGTH_SHORT).show();
}
}
});
Link reading code when app is opened from dynamic link:
Intent intent = getIntent();
Uri uri = intent.getData();
String uriString = uri.toString(); //Used to contain complete link, but now has only BASE LINK CONFIGURED IN FIREBASE
//Extracting parameter from complete link and further processing like fetching data etc.
Ideally I would like to not change the generation code, but if there is no other way, I guess I will have to change that. Thanks!
So, I finally solved this. Turns out this was not an Android version issue, instead for some reason it was happening only in the release APK and not the debug APK. I finally figured out what was happening. In the debug APK, I was receiving the complete link (https:///?id=), but in the release APK, I was only getting the link parameter of the original link (https:///?link=https:///&apn=&afl=&ofl=). So I added my custom generated link in this link parameter as well and it is working correctly now, both on Android 11 and 12 and on the debug APK as well as on the release APK.

Firebase Dynamic links , Define link behaviour programmatically for Android

I'm working with firebase dynamic links on android to generate links programmaticaly when a user shares a specific content .
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject");
sendIntent.setType("text/plain");
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(Uri.parse("https://organization.page.link/?link=https://www.organization.com/content.htm"))
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildShortDynamicLink()
.addOnCompleteListener((Activity) context, task -> {
if (task.isSuccessful()) {
sendIntent.putExtra(Intent.EXTRA_TEXT, task.getResult().getShortLink());
context.startActivity(Intent.createChooser(sendIntent, "Share")));
}
});
Everything works fine here, except when the receiver of the dynamic link doesn't have the app installed , so it redirects him to the website instead of Play Store. I have tried .setFallbackUrl() but it doesn't work.
I have found the problem:
When I use
.setLongLink(Uri.parse("https://organization.page.link/link=https://www.organization.com/content.htm"))
the link is always resolved, then Android opens the URL instead of Play Store . I have replaced that with
.setLink(Uri.parse("www.organization.com/content.htm"))
And adding
.setDynamicLinkDomain("organization.page.link")
Final code
FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLink(Uri.parse("https://organization.com/content.htm"))
.setDynamicLinkDomain("organization.page.link")
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildShortDynamicLink()
.addOnCompleteListener((Activity) context, task -> {
if (task.isSuccessful()) {
// Get Dynamic link here
}
});

How to filter facebook share intent in android?

I have a share button. I share a message with some text and URL. It working well with whatsapp, Twitter and Gmail. But, in facebook share I'm able to share website link only. After, searching on web I have found ShareDialog class for facebook share.My question is how detect (ex: onClick() for facebook icon) when user click facebook icon on android default share dialog. Is it correct way ? or any other alternates is there?
My code :
public void shareApp() {
Intent sendIntent = new Intent();
String websiteLink = "https://www.manam.com";
String playStoreLink = "http://www.google.com";
String msg = "\nHey, found this cool & easy on-demand app.";
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, msg);
sendIntent.putExtra(Intent.EXTRA_TEXT,playStoreLink + msg);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, ""));
}
It's Facebook policy.
When you implement sharing, your app should not pre-fill any content to be shared. This is inconsistent with Facebook Platform Policy, see Facebook Platform Policy, 2.3.
I also don't see an option to detect click on facebook icon. And even if you can show your share dialog you wont be able to prefil any data

Android -- Sharing multiple (two) links using chooser

I want the user to be able to share a link (to text content online). When shared, I also want a link to the app in the Play Store to appear below said link.
Via email, the shared might look like the following
Email subject: [content subject]
Email body:
[link to content]
Download our app here:
[link to app in Play Store]
I tried something like this, but it doesn't display the links:
String playStoreUrl = "market://details?id=" + getActivity().getApplicationContext().getPackageName();
ArrayList<String> links = new ArrayList<String>();
links.add(data.getLink());
links.add(playStoreUrl);
Intent sharingIntent2 = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent2.putExtra(Intent.EXTRA_SUBJECT, content.getSubject());
sharingIntent2.putStringArrayListExtra(Intent.EXTRA_TEXT, links);
sharingIntent2.setType("text/plan");
startActivity(Intent.createChooser(sharingIntent2, "Share this content"));
Any help is much appreciated! There doesn't seem to much documentation on this.
You can do it like this:
String YOUR_TEXT_TO_SEND=data.getLink()+"\n"+"Download our app here: "+"[link to app in Play Store]";
intent.putExtra(Intent.EXTRA_TEXT, YOUR_TEXT_TO_SEND);

How to implement Facebook App Link in Android with example

Is it possible to post on Facebook from my Android application and this post function as App Link? Where if someone using Facebook application tapped on this post it will be directed to G.P. to install my app, and if it's installed it will open my app with enough data to view this post in my app activity?
So far I couldn't find an example that shows how to create an App Link object, and how to include data in this object to be retrieved later from intent -> extras, and I'm totally confused how to implement it in Android.
For example, from my application I want to share an http://youtube.com/xxxxx link in a post on Facebook, how to create the App Link using Facebook App Link host feature?
Edit 1:
I need to understand something about app linking, do I create an app link for each post will be posted from my application, or app link is created once to represent my application?
Edit 2:
How to get my app name to be in Blue as Instagram and clicking on it opens my application or go to my Google Play to install if not installed
Edit 3:
This is the code I use to share, but I don't get my application name a "clickable blue link" as Instagram as in the picture:
ShareDialog shareDialog = new ShareDialog(mMainActivity);
if (ShareDialog.canShow(ShareLinkContent.class))
{
ShareLinkContent linkContent;
if(aURL == null)
{
linkContent = new ShareLinkContent.Builder().build();
}
else
{
linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(aURL))
.build();
}
shareDialog.show(linkContent);
}
Shall I make a specific changes in my application settings page on Facebook dashboard?
You should use open graph actions for that. first you should create a object . then add an action type. then needs to create a story. & you have to submit for review process your facebook app. Normally share code looks like this. read the docs https://developers.facebook.com/docs/sharing/opengraph/android. & you need to use app links - https://developers.facebook.com/docs/applinks/android
// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "books.book")
.putString("og:title", "A Game of Thrones")
.putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
.putString("books:isbn", "0-553-57340-3")
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads")
.putObject("book", object)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
ShareDialog.show(activityOrFragment, content);
If I understand your question correctly, you want to post to facebook(a URL) from your app.
What you can do is:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, your_link_here );
startActivity(Intent.createChooser(intent, "Share via"));
This will open up a list of apps where you can share your link which includes facebook app if it is installed. Also have a look at facebook's TOS. You cannot prefill a message as it is against their policy. If you want to share some text along with your URL you will have to use facebook's SDK.
I tried the same thing. It turns out that your app should be present on app center (facebook). Then only it will turn into blue link.
In my case, I tried clicking the link, but it landed on a page which said:
Misconfigured App Sorry, "My app" hasn't been approved for display in
App Centre.
So I got the hint from this.

Categories

Resources