7

In my application, many link handled in same Activity,

So, I need to know what link when link received.

I know that I will recognize after success listener,

FirebaseDynamicLinks.getInstance()
                .getDynamicLink(intent)
                .addOnSuccessListener(activity, new OnSuccessListener<PendingDynamicLinkData>() {
                    @Override
                    public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                        if (pendingDynamicLinkData != null) {
                            Uri deepLink = pendingDynamicLinkData.getLink();

but, My app's UI thread have to know before success listener, because of UI thread's next operations.

So, I handle intent like that,

if(intent.getExtras() != null
            && intent.getExtras().toString().contains("firebase")) { // this comes from firebase dynamic links.

Could I handle intent in this way? And, Firebase framework will aways put extra data include firebase string?

Could you please, let me know any other solution? The bast ways, I hope to know my apps' host "(app).goo.gl" before success callback..

심현용
  • 71
  • 2
  • Bundle Data like that, B@hashcode aways changed, So I using toString().contains("firebase") Bundle[{com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA=[B@c5ac3a7, com.google.android.gms.appinvite.REFERRAL_BUNDLE=Bundle[mParcelledData.dataSize=456]}] – 심현용 Dec 19 '17 at 02:10
  • I don't believe there is a better way than the approach you've outlined. That said, the best approach would be if you could wait on your dependent UI operations - what prevents putting them in a completion listener? – Ian Barber Dec 20 '17 at 16:07
  • @심현용 Did you find more reliable solution for that? – dor506 Jan 14 '20 at 14:27
  • @dor506 check this article https://deepakdroid.medium.com/firebase-recognize-fdl-before-onsuccesslistener-81e187a9b8dd. I used this approach in my app. – Deepak Goyal Mar 24 '21 at 16:26

2 Answers2

7

You can check if intent extras contains special constant

getIntent().hasExtra("com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA")
Maxdestroyer
  • 185
  • 4
  • 12
0

The accepted answer is actually incorrect. The correct way to check for Firebase Dynamic link is to look inside getIntent().getData(). This will contain a Uri when app is opened via a Firebase Dynamic Link

Kshitij Aggarwal
  • 5,287
  • 5
  • 34
  • 41