creating a dynamic link
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("http://shaharapp.in/"))
.setDynamicLinkDomain("https://cuh8g.app.goo.gl/")
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
// Open links with com.example.ios on iOS
.buildDynamicLink();
dynamicLinkUri = dynamicLink.getUri();
after this, i get a long dynamic link. passing this dynamicLinkUri to shortLinkTask
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(dynamicLinkUri)
.buildShortDynamicLink();
shortLinkTask.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortLink = task.getResult().getShortLink();
link_txt.setText(shortLink.toString());
}
else {
ViewGroup container = (ViewGroup) findViewById(R.id.snackbar_layout);
Snackbar.make(container, "error", Snackbar.LENGTH_SHORT).show();
}
}
});
This task is not completing, after debugging I got this
com.google.android.gms.common.api.ApiException: 7: Bad Request class com.google.android.gms.common.api.ApiException
What is the long link you are getting? I suggest trying long link and ensure the link works correctly.
Also, append &d=1
to long link. Such link will navigate to debug page with possible errors/warnings displayed.
Looking at your code, one possible reason for failure is format of the domain. See example https://firebase.google.com/docs/dynamic-links/android/create . Domain expected to be string containing only domain, without https scheme:
.setDynamicLinkDomain("abc123.app.goo.gl")
Make sure your .setDynamicLinkDomain("https://abc123.app.goo.gl") contains "https://"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With