Firebase dynamic link support custom parameters?

后端 未结 10 1276
野趣味
野趣味 2020-12-29 04:25

I am writing a App for a Open Source Conference.

Originally each attendees will receive different link via email or SMS like

https://example.com/?token=fccfc

相关标签:
10条回答
  • 2020-12-29 04:56

    1 First Change your Dynamic Link in firebase console from http://exampleandroid/test to http://exampleandroid/test?data 2. You send the query paramter data with this

     DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
                       // .setLink(dynamicLinkUri)
                        .setLink(Uri.parse("http://exampleandroid/test?data=dsads"))
                        .setDomainUriPrefix("https://App_Name.page.link")
                        // Open links with this app on Android
                        .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
                        // Open links with com.example.ios on iOS
                        .setIosParameters(new DynamicLink.IosParameters.Builder("com.appinventiv.ios").build())
                        .buildDynamicLink();
    
                dynamicLinkUri = dynamicLink.getUri();
    
    0 讨论(0)
  • 2020-12-29 04:58

    You can add extra parameter to your link to generate Short URL from Firebase. Here I given example of Short URL generation using Firebase API. Here ServiceRequestHelper(this).PostCall is my generic class to make API request

    String url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=YOUR_KEY";
    
        try {
            PackageManager manager = this.getPackageManager();
            PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
            JSONObject jsonObject = new JSONObject();
            JSONObject androidInfoObject = new JSONObject();
            androidInfoObject.put("androidPackageName", getApplicationContext().getPackageName());
            androidInfoObject.put("androidMinPackageVersionCode",String.valueOf(info.versionCode));
    
            JSONObject iosInfoObject = new JSONObject();
            iosInfoObject.put("iosBundleId", "tettares.Test_ID");
            JSONObject dynamicLinkInfoObj = new JSONObject();
            dynamicLinkInfoObj.put("dynamicLinkDomain", "wgv3v.app.goo.gl");
            dynamicLinkInfoObj.put("link", "https://test.in/?UserId=14&UserName=Naveen");  // Pass your extra paramters to here
            dynamicLinkInfoObj.put("androidInfo", androidInfoObject);
            dynamicLinkInfoObj.put("iosInfo", iosInfoObject);
    
            JSONObject suffixObject = new JSONObject();
            suffixObject.put("option" , "SHORT");
            jsonObject.put("dynamicLinkInfo", dynamicLinkInfoObj);
            jsonObject.put("suffix", suffixObject);
    
            Log.d("JSON Object : " , jsonObject.toString());
    
            new ServiceRequestHelper(this).PostCall(url, jsonObject, false, new CallBackJson() {
                @Override
                public void done(JSONObject result) throws JSONException {
    
                    try {
                        if (result.has("shortLink")) {
                            DEEP_LINK_URL = result.getString("shortLink");                                                   }
                    } catch(Exception e)
                    {
                        e.printStackTrace();
                    }
    
                }
            });
    
    
        } catch (JSONException | PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    

    In Your Receiving Activity:

    boolean autoLaunchDeepLink = false;
        AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
                .setResultCallback(
                        new ResultCallback<AppInviteInvitationResult>() {
                            @Override
                            public void onResult(@NonNull AppInviteInvitationResult result) {
                                if (result.getStatus().isSuccess()) {
                                    // Extract deep link from Intent
                                    Intent intent = result.getInvitationIntent();
                                    String deepLink = AppInviteReferral.getDeepLink(intent);
    
                                    // Handle the deep link. For example, open the linked
                                    // content, or apply promotional credit to the user's
                                    // account.
    
                                    // [START_EXCLUDE]
                                    // Display deep link in the UI
                                    Log.d(TAG, "deeplink URL: " + deeplink); // Here you get https://test.in/?UserId=14&UserName=Naveen
                                    // [END_EXCLUDE]
                                } else {
                                    Log.d(TAG, "getInvitation: no deep link found.");
                                }
                            }
                        });
    
    0 讨论(0)
  • 2020-12-29 04:59

    I don't think you can use the short url: https://<my app>.app.goo.gl/Gk3m unless you create one for each user, but you can use the long url: https://<my app>.app.goo.gl/?link=https://example.com/?token=fccfc8bfa07643a1ca8015cbe74f5f17 ...(add other parameters as needed) and set new token for each user.

    I assume you generate the tokens automatically. In that case you can use this to shorten the links.

    0 讨论(0)
  • 2020-12-29 05:04

    Now you can create short links using the Firebase SDK through the FirebaseDynamicLinks.getInstance().createDynamicLink(): https://firebase.google.com/docs/dynamic-links/android/create

    Sample code:

    Task shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
        .setLink(Uri.parse("https://example.com/"))
        .setDynamicLinkDomain("abc123.app.goo.gl")
        // Set parameters
        // ...
        .buildShortDynamicLink()
        .addOnCompleteListener(this, new OnCompleteListener() {
            @Override
            public void onComplete(@NonNull Task task) {
                if (task.isSuccessful()) {
                    // Short link created
                    Uri shortLink = task.getResult().getShortLink();
                    Uri flowchartLink = task.getResult().getPreviewLink();
                } else {
                    // Error
                }
            }
        });
    
    0 讨论(0)
  • 2020-12-29 05:06

    No need of all the hustle

    1. Don't shorten the url if you want to pass parameters
    2. Write the links like this.

      //APP_CODE is firebase link
      String link = "https://APP_CODE.app.goo.gl/?refferer=" + userId;
      
      Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
                      .setMessage(getString(R.string.invitation_custom_message)))
                      .setDeepLink(Uri.parse(link))
                      .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
                      .setCallToActionText(getString(R.string.invitation_cta))
                      .build();
      
      startActivityForResult(intent, REQUEST_INVITE);
      
    0 讨论(0)
  • 2020-12-29 05:07

    I tried all above but none work. So I think you should change the link http://example.com/?userid=123tohttp://example.com/userid/123

    0 讨论(0)
提交回复
热议问题