0

I need to retrieve the short dynamic link when the user clicks on it on Android. But, when the user is clicking on the link I am only receiving the deep link when using the default implementation found on Firebase.

when I used a different approach (Using Get Query), I received null values.

Please advice.

Short dynamic link on firebase

FireBase implementation:

    FirebaseDynamicLinks.getInstance()
                            .getDynamicLink(getIntent())
                            .addOnSuccessListener(SplashActivity.this, new OnSuccessListener<PendingDynamicLinkData>() {
                                @Override
                                public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                                    // Get deep link from result (may be null if no link is found)
                                    Uri deepLink = null;


                                    if (pendingDynamicLinkData != null) {
                                        deepLink = pendingDynamicLinkData.getLink();
                                        Log.e("R4L0",String.valueOf(deepLink));
                                        Log.e("R4L1",String.valueOf(getIntent().getData()));
                                        Log.e("R4L2",pendingDynamicLinkData.toString());
                                    }


                                    // Handle the deep link. For example, open the linked
                                    // content, or apply promotional credit to the user's
                                    // account.
                                    // ...


                                    // ...
                                }
                            })
                            .addOnFailureListener(SplashActivity.this, new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {
                                    Log.w("R4L", "getDynamicLink:onFailure", e);
                                }
                            });


Get uri implementation:

  Uri appLinkData = getIntent().getData();
                    if (!appLinkData.equals(Uri.EMPTY)){
                Log.e("R4L","URL "+String.valueOf(appLinkData.getQuery()));
                String CurrentString = String.valueOf(appLinkData.getQuery());
                String[] separated = CurrentString.split("\\?");
                String[] linkData=separated[1].split("=");

                if (linkData[0].equals("offer")){
                    Log.d("separated",separated[1]);
                    Intent intent = new Intent(SplashActivity.this,Display_Clicked_Offer_Info.class);
                    intent.putExtra("IDITEM",separated[1]);
                    startActivity(intent);
                    finish();
                }
                else if(linkData[0].equals("shop")) {
                }

Using Get Query

Miled Aoun
  • 1
  • 1
  • 3

1 Answers1

0

The reason this doesn't work is that shortlinks don't have a query component!

The format of a Firebase Dynamic Links shortlink is: https://appcode.app.goo.gl/Ab1D - so the actual short code is part of the path.

Under the hood, Firebase sends that shortlink off to the Dynamic Links API, and resolves it back to a long URL. The long URL is very likely to have query parameters.

Ian Barber
  • 19,765
  • 3
  • 58
  • 58