'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!
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Uday Vig |