0

I am new to firebase. I was using an old version code where the parameters i put were atleast working for the url. but now when link is clicked, the browser opens and its a 400 error that requested url was not found. it works with only the dynamic link

 button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Uri BASE_URI = Uri.parse("http://example.com/"); Uri APP_URI = BASE_URI.buildUpon(). appendQueryParameter("extra1", "value").build(); String encodedUri = null; try { encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.v("ENCODED URI: ", encodedUri); Uri deepLink = Uri.parse("https://eh62u.app.goo.gl/y6N7/?link="+encodedUri); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_EMAIL, ""); intent.putExtra(Intent.EXTRA_SUBJECT, "GET TICKETS" ); intent.putExtra(Intent.EXTRA_TEXT, "Click here to get the booked tickets: " + deepLink); startActivity(Intent.createChooser(intent, "Send Email")); } }); } 

Main Activity OnCreate code:

setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button); FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()) .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() { @Override public void onSuccess(PendingDynamicLinkData data) { if (data == null) { Log.d("NULL DATA ", "getInvitation: no data"); return; } // Get the deep link Uri deepLink = data.getLink(); String requestId2 = deepLink.getQueryParameter("extra1"); // Handle the deep link // [START_EXCLUDE] Log.d("DEEP LINK URL ", "deepLink:" + deepLink); if (deepLink != null) { if(requestId2 == "value") { Intent intent = new Intent(getApplicationContext(), Main2Activity.class); startActivity(intent); } } // [END_EXCLUDE] } }) .addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w("onFailure: ", "getDynamicLink:onFailure", e); } }); 

Android Manifest Code:

 <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:host="example.com" android:scheme="https"/> </intent-filter> </activity> <activity android:name=".Main2Activity"> </activity> </application> 

how do i put the parameter and then get it in the onSuccess? Thanks

12
  • Try creating link with builder in console or by code: firebase.google.com/docs/dynamic-links/android/create Commented Oct 16, 2017 at 8:25
  • @DimaRostopira this says that in android the parameters are only minimum app version and fallback url. but i want to add a sort of key with a string value so that i can use it when the app is opened Commented Oct 16, 2017 at 8:32
  • Does it required for you to use params? Can't you use it like https://example.com/value1/value2? Commented Oct 16, 2017 at 8:33
  • @DimaRostopira i dont know if that will work but then how will i get "value1" or "value2" when the app is opened? Commented Oct 16, 2017 at 8:36
  • I'm doing like that url.split('/').last() Commented Oct 16, 2017 at 8:38

1 Answer 1

1

The problem that i finally figured out by trial and error was the encoding part of the code. When i removed the :

encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8"); 

part and just passed APP_URI to the deep link like

Uri deepLink = Uri.parse("https://eh62u.app.goo.gl/y6N7/?link="+APP_URI); 

or even constructing the link using builder as:

Uri.Builder URLbuilder = new Uri.Builder() .scheme("https") .authority(Constants.DOMAIN) .path("/") .appendQueryParameter("link", getBaseUri(value)) .appendQueryParameter("apn", context.getPackageName()); 

It worked. No Problems. Retrieving the parameter was the usual.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.