Android Firebase Dynamic links not working in Facebook messenger properly - android

I integrated my application with dynamic links from firebase successfully. But when I share a short link with SocialMetaTagParameters and click on the link in messenger it opens the browser and it should redirected to my application, but it is entering in infinite loop in the browser.
I found similar issue created in google groups:
https://groups.google.com/forum/#!topic/firebase-talk/nOOcOwmxl58
This is my code to create short link:
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain(mContext.getString(R.string.firebaseAppCode))
// Set parameters
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.setIosParameters(new DynamicLink.IosParameters.Builder("com.xxxx.xxxx").build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle(title)
.setDescription(description)
.setImageUrl(Uri.parse(imageUrl))
.build()
)
.buildShortDynamicLink()
.addOnCompleteListener((Activity) mContext, new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
// Short link created
Uri shortLink = task.getResult().getShortLink();
ShareApp(mContext, shortLink.toString());
} else {
Utils.ShowToast(mContext, "Sharing failed, Try again");
}
}
});
This is my code to share the short dynamic link:
public static void ShareApp(Context mContext,String link) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT,link);
mContext.startActivity(Intent.createChooser(share, "Share..."));
}
This is code in manifest :
<activity
android:name=".UI.Home.Consultants.ViewConsultantProfileActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="Profile"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="consultrustconsultant"
android:scheme="http"/>
<data
android:host="consultrustconsultant"
android:scheme="https"/>
</intent-filter>
</activity>
Note:
if I removed SocialMetaTagParameters, the link is working properly and when click on the link its redirected to my application

Related

Deep link not opening specified Activity but opens other Activity

I have created a DynamicLink programatically which includes sub-domain syntax, some title and preview Image. I have also specified the IntentFilter which should open that activity when clicked. But when the link is clicked it open another Activity which also have Deep link. page.link domain is provided by google itself in Firebase Console
The code for creating Dynamic Link is
String e="https://learnandroid.page.link/?link=https://learn.android/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLongLink(Uri.parse(e))
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
Uri get=task.getResult().getShortLink();
Intent sh=new Intent(Intent.ACTION_SEND);
sh.setType("text/plain");
sh.putExtra(Intent.EXTRA_TEXT,"Vi ew the Amazing Event "+get);
startActivity(Intent.createChooser(sh,"View"));
}
});
The Intent filter for Activity is given as
<activity android:name=".content.Home"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="learn.android"
android:scheme="https" />
</intent-filter>
</activity>
But when the link generated is clicked it opens some Another activity.
If you have deeplink in multiple activities then you should use android:pathPattern to differentiate them from each other.
Here is sample code
<data
android:host="learn.android"
android:pathPattern="/home"
android:scheme="https" />
and add /home to your link
String e="https://learnandroid.page.link/?link=https://learn.android/home/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
You can try below snippet :
val data: Uri? = intent?.data
if (Uri.EMPTY != data)
{
val id = intent.data?.getQueryParameter("ID")
intent = Intent(this, ActivityName::class.java)
startActivity(intent)
finish()
}
In getQueryParameter, you need to pass KEY name which contains data in URL
Define this set of code in Activity which is defined in Manifest file

how to redirect user to play store when we click on app link shared to whatsapp when particular app is not in his device

This is the link which i created to share an url of a particular product in java class
String url="http://www.example.com/productId/";
String finalurl = url + productId.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("*/*");
i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
i.putExtra(Intent.EXTRA_TEXT, name.getText().toString()+ "\n" + finalurl);
startActivity(Intent.createChooser(i, "Share Image"));
this is the intent filter that has created to an activity through App links Assistant
<activity
android:name=".login.Launchscreen"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPrefix="/productId"
android:scheme="http" />
</intent-filter>
<tools:validation testUrl="http://www.example.com/productId/" />
</activity>
this is the java code through which i can extract the data which i appended to my link
Intent intent = getIntent();
String appLinkAction = intent.getAction();
Uri appLinkData = intent.getData();
if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) {
proid = appLinkData.getLastPathSegment();
}
through above code i can share url through whatsapp and when i click on the shared app link it is redirecting to my app successfully but what i need is i want to redirect the user to play store when my application is not in his device and when the application is in his device he should be navigated to particular activity. can anyone help me please.All i want is in android app.Thanks in advance
You can check whether app is installed or not using package manager
final boolean isAppInstalled = appInstalledOrNot(\\ your URL package name\\);
private boolean appInstalledOrNot(String packagname) {
PackageManager pm = getActivity().getPackageManager();
try {
pm.getPackageInfo(packagname, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
// now check on your button click
if (isAppInstalled)
{
Intent LaunchIntent = getContext().getPackageManager().getLaunchIntentForPackage(\\ your URL package name\\);
getContext().startActivity(LaunchIntent);
} else {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(\\your URL\\));
} catch (android.content.ActivityNotFoundException anfe) {
anfe.printStackTrace();
}
}
you can use branch.io for create deep link and check app is not install go
to play store.
https://branch.io/how-branch-links-work/
step 1: Above link sign up
step 2: open branch dashboard
step 3. select Set Up SDK then open new page that page select your device
step 4: if you select android open new page that page contain this option
follow this
1.Enter app information
2.Get the SDK files
3.Configure Manifest
4.Start a Branch session
step 5: come back to dashboard see first option LIVE and TEST
1.you click live then select Account Setting see live key
2.you click test then select Account Setting see test key
<meta-data
android:name="io.branch.sdk.BranchKey"
android:value="put live key" />
<meta-data
android:name="io.branch.sdk.BranchKey.test"
android:value="put test key" />
if use test key for testing perpose, if you go to live set false
<meta-data
android:name="io.branch.sdk.TestMode"
android:value="true" />
step 6: go to link setting
1.see android
1.select two check box one I have an Android App and Enable app link
2.see Android URI Scheme enter your uri for if you install the app
you click the deep link open the app.
(example:appName://open)
3.see google play search for if you not install the app then redirect to
google play store
1.first you upload app to play store then search and set
4.set SHA256 Cert Fingerprints
5.see link domain option
1.use Default Link Domain link
<activity
android:name=".MainActivity"
android:alwaysRetainTaskState="true"
android:configChanges="orientation"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="#style/MyAppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="open"
android:scheme="set your android Scheme uri" />
<data
android:host="Default Link Domain link"
android:pathPrefix="/"
android:scheme="https" />
</intent-filter>
</activity>
step 7: click deep link handle on MainAtivity
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
// Branch init
branch.initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
if(referringParams.has("post_id")){
mPostId = referringParams.getString("post_id");
}
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
step 8: create deep link for post or news in your app
try {
BranchUniversalObject buo = new BranchUniversalObject()
.setCanonicalIdentifier("app/launch")
.setTitle("appName")
.setContentDescription(postContent)
.setContentImageUrl(imageUrl)
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
.setContentMetadata(new ContentMetadata()
.addCustomMetadata("install", "true")
.addCustomMetadata("TYPE", "POST")
.addCustomMetadata("post_id", "" + postId));
LinkProperties lp = new LinkProperties().setChannel("url_share")
.setFeature("sharing")
.setCampaign("post share")
.setStage("cricspace")
.addControlParameter("$desktop_url", "your app web link")
.addControlParameter("mobile", mobileNo)
.addControlParameter("post_id", "" + postId)
.addControlParameter("TYPE", "POST")
.addControlParameter("custom_random",
Long.toString(Calendar.getInstance().getTimeInMillis()));
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(context, "Check this
out!", postContent)
.setCopyUrlStyle(context.getResources().
getDrawable(android.R.drawable.ic_menu_send), "Copy", "Added to
clipboard")
.setMoreOptionStyle(context.getResources().
getDrawable(android.R.drawable.ic_menu_search), "Show more")
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.WHATS_APP)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.GMAIL)
.addPreferredSharingOption
(SharingHelper.SHARE_WITH.FACEBOOK_MESSENGER)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.HANGOUT)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.INSTAGRAM)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.WECHAT)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.TWITTER)
.setAsFullWidthStyle(true)
.setSharingTitle("Share With");
// buo.setContentDescription(postModel.getPostContent()+"\n\n"
+deepLinkReferralURL );
buo.generateShortUrl(context, lp, (url, error) -> {
if (error == null) {
buo.showShareSheet((AppCompatActivity) context, lp,
shareSheetStyle, new Branch.BranchLinkShareListener() {
#Override
public void onShareLinkDialogLaunched() {
onCallBack.onShareLinkDialog();
}
#Override
public void onShareLinkDialogDismissed() {
}
#Override
public void onLinkShareResponse(String sharedLink, String
sharedChannel, BranchError error) {
}
#Override
public void onChannelSelected(String channelName) {
}
});
}
});
} catch (Exception e) {
Log.e("error", e.toString());
}

How to show my app in chooser apps when someone clicks firebase dynamic link?

How should be my android manifest file if I want to show my app in the chooser apps if someone clicks the dynamic link? The URL prefix is like -
https://testapp.page.link. At that stage if someone clicks the link then it first opens the browser then it redirects to my app. But I want to show my app in the chooser app list. At this time my manifest file is like follows-
<activity android:name=".extraActivities.DynamicLinkActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="test.com"
android:pathPattern="https://testapp.page.link*"
android:scheme="https"
/>
</intent-filter>
</activity>
We need to write intent-filter in the manifest file as follows-
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="testapp.com"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="testapp.page.link"
android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
Where "testapp.page.link" is the actually the URL prefixes shown at the top left corner of Firebase dynamic link console. And "testapp.com" is the first part of any link. Eg: https://testapp.com/user_profile?id="Zsdsdjwenncsdmsd". From this link, we can extract the user Id as "Zsdsdjwenncsdmsd" at the receiving end of the dynamic link. A complete example is shown below-
If anyone clicks share button this will create the dynamic link-
shareBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
shareProgressBar.setVisibility(View.VISIBLE);
Task<ShortDynamicLink> shortDynamicLinkTask = buildDeepLink(getString(R.string.grp_post_link)+postsModel.getPostId()+"&groupKey="+postsModel.getGroupKey()+"&groupName="+ dataSnapshot.getValue(String.class));
shortDynamicLinkTask.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
grpPostsViewHolder.shareProgressBar.setVisibility(View.GONE);
if(task.isSuccessful()){
Uri uri = task.getResult().getShortLink();
share(dataSnapshot.getValue(String.class), uri.toString());
}else {
Toast.makeText(context, "Can't create link", Toast.LENGTH_SHORT).show();
}
}
});
shortDynamicLinkTask.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
shareProgressBar.setVisibility(View.GONE);
}
});
The dynamic link creator function and share function-
/*-----------------------------------------------------------------------------*/
private Task<ShortDynamicLink> buildDeepLink(String deepLink) {
String uriPrefix = getString(R.string.dynamic_links_uri_prefix);
return FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(deepLink))
.setDomainUriPrefix(uriPrefix)
.setNavigationInfoParameters(new DynamicLink.NavigationInfoParameters.Builder()
.build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder()
.setMinimumVersion(3)
.build())
.buildShortDynamicLink();
}
/*-----------------------------------------------------------------------------*/
private void share(String name, String deepLink) {
String message = "Find "+name+" on SelfieLe - link: "+deepLink;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
}
/*---------------------------------------------------------------------------------*/
The String resources are-
R.string.grp_post_link, and R.string.dynamic_links_uri_prefix:
<string name="user_profile_link">https://testapp.com/user_profile?id=</string>
<string name="dynamic_links_uri_prefix">https://testapp.page.link</string>
At receiving end we can extract postId, groupKey etc as follows
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
if (deepLink != null) {
getGrpPost(deepLink.getQueryParameter("id"), deepLink.getQueryParameter("groupKey"), deepLink.getQueryParameter("groupName"));
}else {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
});
The getGroupPost(); is as follows
private void getGrpPost(String id, String groupKey, final String groupName) {
//Do what you want
}

how to implement Facebook sharing and then deep link that post using deep link(open my app) in android App?

I want to implement deep linking for facebook app post.
Firstly I want to share my App content on Facebook Post and when user tap on the post then if User already has the app installed then open app otherwise It will open app link.
I follow https://developers.facebook.com/docs/applinks/android and https://developers.facebook.com/docs/sharing/android#linkshare but It's not working
how to share this data using LinkShare on facebook
target_url: "https://developers.facebook.com/android"
extras:
fb_app_id: [YOUR_FACEBOOK_APP_ID]
fb_access_token: "[ACCESS_TOKEN]"
fb_expires_in: 3600
To implement deep linking and sharing together, need to implement this feature using branch.io
Add dependency :
compile 'com.google.android.gms:play-services-appindexing:9.+'
Add this code in the manifest file inside Launcher Activity
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="androidexample" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links (optional) -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="example.app.link" />
<data android:scheme="https" android:host="example-alternate.app.link" />
</intent-filter>
Add this code to your Launcher Activity, You will get your link and data in this method
#Override
public void onStart() {
super.onStart();
// Branch init
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
Log.i("BRANCH SDK", referringParams.toString());
// Retrieve deeplink keys from 'referringParams' and evaluate the values to determine where to route the user
// Check '+clicked_branch_link' before deciding whether to use your Branch routing logic
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
Add this code in MyApplication class
// Branch logging for debugging
Branch.enableLogging();
// Branch object initialization
Branch.getAutoInstance(this);
You can create deep link using this code
LinkProperties lp = new LinkProperties()
.setChannel("facebook")
.setFeature("sharing")
.setCampaign("content 123 launch")
.setStage("new user")
.addControlParameter("$desktop_url", "http://example.com/home")
.addControlParameter("custom", "data")
.addControlParameter("custom_random",
Long.toString(Calendar.getInstance().getTimeInMillis()));
buo.generateShortUrl(this, lp, new
Branch.BranchLinkCreateListener() {
#Override
public void onLinkCreate(String url, BranchError error) {
if (error == null) {
Log.i("BRANCH SDK", "got my Branch link to share: " + url);
}
}
});
refer this for Android
refer this for ios

How to use facebook mobile hosting api to create app link in facebook sdk android

I've preferred the below link to create a link object and app link but unfortunately i could not able to find anything from this link
Mobile Hosting Api. So please guys can you please tell me the exact steps to create the app link for my mobile application.
Here is the manifest code for the activity
<activity android:name=".AppLinkActivity"
android:label="#string/app_name" >
...
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.GoCarDev" />
</intent-filter>
</activity>
and here is the Activity on which i have to redirect the app link
FacebookSdk.sdkInitialize(this);
Uri targetUrl =
AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
Toast.makeText(this, "Link" + targetUrl, Toast.LENGTH_SHORT).show();
if (targetUrl != null) {
Log.i("Activity", "App Link Target URL: " + targetUrl.toString());
} else {
AppLinkData.fetchDeferredAppLinkData(
this,
new AppLinkData.CompletionHandler() {
#Override
public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
//process applink data
}
});
}
Thank you guys in advance

Categories

Resources