Issues in configuring Firebase deeplinks in my app

652 views Asked by At

i am trying to configure firebase dynamic links in my app but facing few issues.

I did the following : 1. Set up of Firebase console done. 2. My code in manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.manpsing.deeplinkdemo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        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>

            <!-- [START link_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>
            <!-- [END link_intent_filter] -->
        </activity>
    </application>

</manifest>
  1. Code in main activity :

    public class MainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {

    private static final String TAG = "MainActivity";
    private static final String DEEP_LINK_URL = "https://example.com/deeplinks";
    
    // [START define_variables]
    private GoogleApiClient mGoogleApiClient;
    // [END define_variables]
    
    // [START on_create]
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // [START_EXCLUDE]
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        // Validate that the developer has set the app code.
        validateAppCode();
    
        // Create a deep link and display it in the UI
        final Uri deepLink = buildDeepLink(Uri.parse(DEEP_LINK_URL), 0, false);
        ((TextView) findViewById(R.id.link_view_send)).setText(deepLink.toString());
    
        // Share button click listener
        findViewById(R.id.button_share).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDeepLink(deepLink.toString());
            }
        });
        // [END_EXCLUDE]
    
        // [START build_api_client]
        // Build GoogleApiClient with AppInvite API for receiving deep links
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(AppInvite.API)
                .build();
        // [END build_api_client]
    
        // [START get_deep_link]
        // Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
        // would automatically launch the deep link if one is found.
        boolean autoLaunchDeepLink = false;
        AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
                .setResultCallback(
                        new ResultCallback<AppInviteInvitationResult>() {
                            @Override
                            public void onResult(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
                                    ((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
                                    // [END_EXCLUDE]
                                } else {
                                    Log.d(TAG, "getInvitation: no deep link found.");
                                }
                            }
                        });
        // [END get_deep_link]
    }
    
  2. My strings.xml file is like :

    DeeplinkDemo

    <!--
      Your app code, see:
      https://firebase.google.com/docs/dynamic-links/android
    -->
    <string name="app_code">pgm3j</string>
    
    
    <string name="share">Share</string>
    <string name="title_receive">Receive</string>
    <string name="title_send">Send</string>
    <string name="msg_no_deep_link">No deep link received.</string>
    

I guess i haven't created a dynamic link in this. Please help me how to create one. Also let me know how to use this dynamic links i.e which url i need to open and where it will point to .

Moreover when i am trying to install this app in device,it is not getting installed.I don't know the reason why it is not installing.

Thanks

1

There are 1 answers

4
Ian Barber On BEST ANSWER

There are two bits to handling Dynamic Links:

1) Handling Regular Deeplinks

This means making your app handle URLs. You've added an intent filter for example.com, which is in the right direction but you need to replace that with your our domain in there. If you don't have one, you can use the [yourproject].firebaseapp.com that comes with your Firebase project!

2) Parse received URLs

This is what your AppInviteApi code is doing so you're good here - parsing the Intent generated from the opened URL, and extracting a deeplink. For a production app, the same code will also retrieve the data passed through the Play store, so the link works even if the user had to install the app.

Finally, the easiest way to generate a link is to use the dynamic links part of Firebase Console.