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

L3G3NDj
  • 35
  • 9

1 Answers1

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.

L3G3NDj
  • 35
  • 9